3

I'm working on something that involves placing plot sketches side by side. The trouble is, even though I begin the next picture on the same line as the previous one ends, it doesn't look nice:

\begin{tikzpicture}

\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Guy};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\draw (0,-1) -- (1,0) -- (2,1);

\end{tikzpicture} \begin{tikzpicture}

\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Car};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\draw [domain=0:0.89] plot (\x, {2.5*\x*\x});

\end{tikzpicture}

What is wrong, and how can I fix it?

3
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Adam Liter
    Sep 8, 2014 at 3:56
  • 1
    Add [baseline] to each of your \begin{tikzpicture}'s (i.e., they should be \begin{tikzpicture}[baseline] instead of \begin{tikzpicture}), and this should solve your problem.
    – Adam Liter
    Sep 8, 2014 at 3:59
  • 1
    Will do. Thanks for the help; but just curiously, I must ask what does baseline do exactly? About what axis does it center the graphs?
    – user11629
    Sep 8, 2014 at 4:10

1 Answer 1

7

For the sake of illustration, it will be easiest to make your tikzpicture's appear inlign with some text. Normally, the bottom of a tikzpicture is put on the baseline of the surrounding text. So, if we take your code and add A and B on either side, we get:

enter image description here

This makes sense. The lowest point in the first tikzpicture (i.e., the bottom end of the plotted line) is aligned with the baseline of the text, and the lowest point of the second tikzpicture (i.e., the bottom of the label for the x-axis) is also aligned with the baseliene of the surrounding text.

However, you can change this alignment with the TikZ style baseline, which allows you to specify what point will be put on the baseline of surrounding text. baseline is short for baseline=0pt, which puts the x-axis of the tikzpicture on the baseline of the surrounding text:

enter image description here

As you can see, the x-axis is what is aligned to the baseline of the surrounding text. Here's the code for this. (Again, baseline=0pt is the same as baseline.)

MWE

\documentclass{article}

\usepackage{tikz}

\begin{document}

A \begin{tikzpicture}[baseline=0pt]

\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Guy};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\draw (0,-1) -- (1,0) -- (2,1);

\end{tikzpicture} \begin{tikzpicture}[baseline=0pt]

\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Car};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\draw [domain=0:0.89] plot (\x, {2.5*\x*\x});

\end{tikzpicture} B

\end{document}

Rather than specifying a particular dimension for baseline, you can also specify a coordinate. For complete details, see page 125 of the current TikZ documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.