I'm experimenting with importing some tikzpicture into a PowerPoint using IguanaTeX.
This is the code I am experimenting with:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}[scale=0.50,local bounding box=picture, baseline=(picture.south),
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,40},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,40,0.2)}; \addlegendentry{$p=0.2$}
\addplot [fill=orange, fill opacity=0.5] {binom(x,40,0.5)}; \addlegendentry{$p=0.5$}
\end{axis}
\end{tikzpicture}
\end{document}
Note to get it to appear correctly, you need to change from the default DVI to pdflatex in IguanaTeX.
Firstly, the graph appears BUT there is some unnecessary whitespace that occurs at the bottom. As such, the resulting graphic is too large for the slide. How can I remove this?
Secondly, how can I change the axes etc. to be displayed in white, instead of the default black, so I can see the graph on a PowerPoint slide with a black background?
you can avoid the space between your graph and the axis by setting ymin=0
to change axis, labels, legend etc. to white, you can make the following adjustments:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\pgfplotsset{
axis line style={white},
every axis label/.append style ={white},
every tick label/.append style={white},
every axis legend/.append style={white,fill=black},
every axis/.append style={tick style={white}}
}
\pagecolor{black}
\begin{document}
\begin{tikzpicture}[scale=0.50,local bounding box=picture, baseline=(picture.south),
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,40},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1,
ymin=0,
]
\addplot [fill=cyan, fill opacity=0.5,draw=white] {binom(x,40,0.2)}; \addlegendentry{$p=0.2$}
\addplot [fill=orange, fill opacity=0.5,draw=white] {binom(x,40,0.5)}; \addlegendentry{$p=0.5$}
\end{axis}
\end{tikzpicture}
\end{document}
Related
My question is how we can put a tikzpicture shapes in specific position in latex slides? I mean I do not want to change the position of texts in slide but draw a shape in a specific position. (like powerpoint)
If you use the overlay option, your tikz picture won't influence the rest of the text:
\documentclass[aspectratio=169]{beamer}
\usepackage{tikz}
% trick taken from https://topanswers.xyz/tex?q=1989
\tikzset{
use page relative coordinates/.style={
shift={(current page.south west)},
x={(current page.south east)},
y={(current page.north west)}
},
}
\begin{document}
\begin{frame}
some text, does not change position
\begin{tikzpicture}[remember picture, overlay,use page relative coordinates]
\fill[red] (0.7,0.3) circle [radius=0.5cm];
\end{tikzpicture}%
\end{frame}
\end{document}
I would like to add images in the top left/right or bottom left/right in a two-column page while ignoring the margins and having the text wrap around the picture. How can I also extend the solution to include half page images while ignoring the margins and with text wrapping.
I tried tikz package, but the text doesn't wrap around even when I use the wrapfig package.
For example, this is the code I used to insert image on the top left side of the page:
\documentclass[twocolumn, 12pt]{book}
\usepackage{lipsum}
\usepackage{tikz}
\begin{document}
\lipsum[1-3]
\begin{tikzpicture} [remember picture, overlay]
\node[anchor=north west,yshift=-1.5pt,xshift=1pt]%
at (current page.north west)
{\includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{example.jpg}};
\end{tikzpicture}
\lipsum[1-3]
\end{document}
This results in the picture at the desired position, but the text is obscured behind the image. Thank you!
Not very pretty, but does the job I think (using geometry package only to get the correct values for top margin):
\documentclass[twocolumn, 12pt]{book}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{geometry}
\begin{document}
\begin{tikzpicture} [remember picture, overlay]
\node[anchor=north west]%
at (current page.north west)
{\includegraphics[width=0.46\paperwidth,height=0.5\paperheight]{example.png}};
\end{tikzpicture}
\vspace*{\dimexpr(0.5\paperheight-\voffset-1in-\headsep-\headheight)}
\lipsum[1-3]
\lipsum[1-3]
\end{document}
I am trying to use the subfigure method shown at https://www.latex-tutorial.com/tutorials/figures/ to make side by side plots but I can't seem to adjust the size and get them to go side by side...what am i doing wrong?
Below is code I am using
\begin{figure}
\centering
\begin{subfigure}[b!]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[
axis y line = middle,
axis x line = middle,
xlabel = $x$,
ylabel = {$f(x) = x^3$},
grid=major,
]
\addplot [
domain=-3:3,
samples=100,
color=red,
]
{x^3};
\addlegendentry{$x^3$}
%
\addplot [
domain=-3:3,
samples=100,
color=blue,
]
{x^3 + 3};
\addlegendentry{$x^3 + 3$}
%
\addplot [
domain=-3:3,
samples=100,
color=green,
]
{x^3 - 3};
\addlegendentry{$x^3 - 3$}
\end{axis}
\end{tikzpicture}
\end{subfigure}
%\hfill
\begin{subfigure}[b]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[
axis y line = middle,
axis x line = middle,
xlabel = $x$,
ylabel = {$f(x) = x^3$},
grid=major,
]
\addplot [
domain=-3:3,
samples=100,
color=red,
]
{x^3};
\addlegendentry{$x^3$}
\end{axis}
\end{tikzpicture}
\end{subfigure}
\caption{lajsdfls}
\end{figure}
There are two problems with your code.
First horizontal alignment of the figures was incorrect, but this can easily be fixed by using
\begin{subfigure}[b]{0.3\textwidth}
instead of
\begin{subfigure}[b!]{0.3\textwidth}
concerning the width, what is done when you create a subfigure environment is that a minipage of the indicated width is created. But is is up to you to respect this width with your content, no rescaling is done.
For instance, if, in a subfigure, you include an image and give it a width of \linewidth, the width will be respected. But if you give this image a 15cm width, probably it will be larger than you minipage. But LaTeX will respect your directives (and indicate an overfull hbox).
This is the problem that you have. Your plots are too large and overlap.
There are two ways to fix that.
You can give a width=\linewidth parameter to the axis environment, but it generally requires a redesign of your plot
you can rescale the box created by tikz. The most flexible way to do that is with adjustbox package
\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{adjustbox}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.45\textwidth}
%%% \begin{adjustbox}{width=\linewidth} % rescale box
\begin{tikzpicture}
\begin{axis}[
%%% width=\linewidth, % or modify the plot width
axis y line = middle,
...
...
\end{axis}
\end{tikzpicture}
%%% \end{adjustbox} %
\end{subfigure}%
\hfill
\begin{subfigure}[b]{0.45\textwidth}
etc.
Adding a width parameter to the axis environment
Rescaling with adjustbox
BTW, if you do not intend to add subcaptions to your plots, the subfigure environment is useless, and you can just put your (properly scaled) tikzpictures side by side separated by an \hfill.
I create a simple diagram in Latex (tikzpicture) and some labels on the y-axis overlap as you can see in the picture
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
title=\textbf{example},
ybar,
width=10cm, height=5cm, bar width=30pt,
enlargelimits=0.5,
symbolic x coords={2013,2014,2015,2016}, xtick={2013,2014,2015,2016},
ytick=data,
]
\addplot coordinates
{(2013,794) (2014,1208) (2015,1183) (2016,1259)};
\end{axis}
\end{tikzpicture}
\end{figure}
How can I fix this, I don't want to make the diagram much higher?
I suggest to trust pgfplots to create readable axis labels instead of manually interfering:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\begin{axis}[
title=\textbf{example},
ybar,
width=10cm, height=5cm, bar width=30pt,
enlargelimits=0.5,
symbolic x coords={2013,2014,2015,2016}, xtick={2013,2014,2015,2016},
% ytick=data,
]
\addplot coordinates
{(2013,794) (2014,1208) (2015,1183) (2016,1259)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
If you really need to show the exact numerical values, a plot might not be the suitable form of visualization and a table might be better suited.
I'm trying to create a Diagram with following specification:
x-Axis: Values from file.
y-Axis: Quantity of the values
Here is an image to describe, what I need.
The order of the values is random.
I hope, anybody can help me with this problem.
Here is an example.
\documentclass[paper=a4,12pt,version=last]{scrartcl}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0,
x tick label style={/pgf/number format/1000 sep=},
xlabel={values},
y tick label style={/pgf/number format/1000 sep=},
ylabel={amount of values}]
\addplot table [ ... ,col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
Instead of the three points shall be a command to calculate the y-values.
In the data-file are the values in one clolumn.