# Aligning Tikz Graphs of x-y coordinate systems

I have 5 different x-y coordinate planes I am trying to draw, and I'd like to have them aligned. In particular, I'd like to make 3 in one row, 2 in the next, and have the x-axes all aligned within the same row. I have made the graphs and put them in two separate rows, but I cannot get them align nicely.

Here is a minimum working example:

\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}
\usepackage{tabularx}

\begin{document}

\begin{tabular}{ccc}
\begin{tikzpicture}[scale=0.175]
\draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.5:3] plot (\x, {4+3* \x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(A)}; \end{tikzpicture}  &
\noindent  \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6);
\node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};
\draw[green, ultra thick, domain=-1.3:2.6] plot (\x, {-2+3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(B)}; \end{tikzpicture} &
\noindent \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0);
\draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.5:1.05] plot (\x, {-2+3*\x+2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(C)}; \end{tikzpicture} \\[1em]
\noindent \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.6:2.9] plot (\x, {0+3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(D)}; \end{tikzpicture} &
\noindent \begin{tikzpicture}[scale=0.175] \draw[<->] (-4,0)--(4,0);
\draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.3:0.8] plot (\x, {-2-3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(E)};
\end{tikzpicture} &
\\
\end{tabular}

\end{document}

-
Didn't I answer this in chat a while back? – Torbjørn T. Jan 14 '14 at 16:10
Yes I believe somewhat. Would you please mind posting the answer again? I did not fully follow it at the time. I don't want to be unappreciative of the time you took then. I figure others might find it beneficial as well. – J G Jan 14 '14 at 16:11

Short version: Add baseline={(0,0)} as an option to each tikzpicture.

Longer version:

Each tikzpicture is just a box, and the bottom of each box is aligned, the baseline is the bottom of the box. baseline={(0,0)} changes the baseline to be the level where the origin, i.e. (0,0), is in the tikzpicture, making this the reference, not the bottom of the box.

Hence, change each

 \begin{tikzpicture}[scale=0.175]


to

 \begin{tikzpicture}[scale=0.175,baseline={(0,0)}]


Complete code is below. The \noindents doesn't do anything, so I removed them.

\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}

\begin{document}

\begin{tabular}{ccc}
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}]
\draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.5:3] plot (\x, {4+3* \x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(A)}; \end{tikzpicture}  &
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6);
\node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};
\draw[green, ultra thick, domain=-1.3:2.6] plot (\x, {-2+3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(B)}; \end{tikzpicture} &
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);
\draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.5:1.05] plot (\x, {-2+3*\x+2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(C)}; \end{tikzpicture} \\[1em]
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.6:2.9] plot (\x, {0+3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(D)}; \end{tikzpicture} &
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);
\draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.3:0.8] plot (\x, {-2-3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(E)};
\end{tikzpicture} &
\end{tabular}

\end{document}


There is a lot of repetition in your code, each tikzpicture has basically the same layout, with a different function plotted in each. You could create a new command that creates such plots for you given a domain and a function. Below is an example using pgfplots. (Not sure why exactly I used pgfplots and not your code ...)

Added the other code as well, for comparison.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}

\newcommand\myplot[3][]{% 1st arg: label in axis, 2nd arg: domain, 3rd arg: function
\begin{tikzpicture}[baseline={(0,0)}]
\begin{axis}[
axis lines=middle,
x axis line style={<->},
y axis line style={<->},
xtick=\empty, ytick=\empty,
width=1.2cm,  % set width of axis
height=2cm,   % set height of axis
scale only axis,
xmin=-4,xmax=4,
ymin=-6,ymax=6,
xlabel={$x$},
ylabel={$y$},
domain=#2,
clip=false,
anchor=center,
xlabel style={at={(axis cs:4,0)},right},
ylabel style={at={(axis cs:0,6)},above},
]
\node at (axis cs:-3,4) {#1};
\end{axis}
\end{tikzpicture}}

\begin{document}
\begin{tabular}{ccc}
\myplot[(A)]{-1.5:3}{4 + 3*x - 2*x^2} &
\myplot[(B)]{-1.3:2.6}{-2 + 3*x - 2*x^2} &
\myplot[(C)]{-2.5:1.05}{-2 + 3*x + 2*x^2} \\
\myplot[(D)]{-1.6:2.9}{3*x - 2*x^2} &
\myplot[(E)]{-2.3:0.8}{-2 - 3*x - 2*x^2}
\end{tabular}

\begin{tabular}{ccc}
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}]
\draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.5:3] plot (\x, {4+3* \x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(A)}; \end{tikzpicture}  &
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6);
\node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};
\draw[green, ultra thick, domain=-1.3:2.6] plot (\x, {-2+3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(B)}; \end{tikzpicture} &
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);
\draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.5:1.05] plot (\x, {-2+3*\x+2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(C)}; \end{tikzpicture} \\[1em]
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0); \draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-1.6:2.9] plot (\x, {0+3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(D)}; \end{tikzpicture} &
\begin{tikzpicture}[scale=0.175,baseline={(0,0)}] \draw[<->] (-4,0)--(4,0);
\draw[<->] (0,-6)--(0,6); \node at (4.5,0) {$x$};
\node at (0,6.5) {$y$};  \draw[green, ultra thick, domain=-2.3:0.8] plot (\x, {-2-3*\x-2*\x*\x});
\draw[very thick,black](-0.3,3.95) node[left=1pt]{(E)};
\end{tikzpicture} &
\end{tabular}

\end{document}

-
Thank you for this revised example! Two changes seem to have been made, however. The first is that the bottom and left arrows from the axes seems to no longer be there. Second, the 0.175 scale seems to have been removed. I had added that because that was about the appropriate size I had wanted in the document, but I suppose you are suggesting a different strategy? I only say that because now the dimensions no longer seem to math the stretch that I previously had. Of course though your code is infinitely easier to manage than mine. – J G Jan 14 '14 at 17:18
@JG Sorry, didn't really think about size. You can set the width and height of the axes explicitly, see the options to the axis environment. I'll update my code in a minute or two to fix the arrow heads as well. – Torbjørn T. Jan 14 '14 at 19:06