2

I have two tikzpictures:

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}

\tikzstyle{notarget} = [rectangle, rounded corners, minimum
  width=1cm, minimum height=1cm,text centered, draw=none,
  opacity=0,text opacity=1,align=center]
\tikzstyle{target} = [rectangle, rounded corners, minimum width=1cm, minimum
  height=1cm,text centered, draw=black, very thick,text
  opacity=1,align=center]

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \begin{tikzpicture}[node distance=1.2cm]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right of=n1] {saw\\VBD};
      \node (n3) [target, right of=n2] {a\\DT};
      \node (n4) [target, right of=n3] {girl\\NN};
%      \draw [thick,->] (n4) -- ++(1cm,0);
    \end{tikzpicture}
    \caption{}
  \end{subfigure}
  \qquad\qquad
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \begin{tikzpicture}[node distance=1.2cm]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right of=n1] {saw\\VBD};
      \node (n3) [target, right of=n2] {a\\DT};
      \node (n4) [target, below of=n3,anchor=north] {girl\\NN};
      \draw [thick,->] (n4) -- (n3);
    \end{tikzpicture}
    \caption{}
  \end{subfigure}
  \label{fig:rightaction}
\end{figure}
\end{document}

But I do not know how to align the to figures vertically, currently it shows like this:

enter image description here

I would like to align it like this:

enter image description here

I have tried the following answers, without success:

UPDATE

I get it working with the help of Guilherme, here is:

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.4\textwidth}
    \begin{tikzpicture}[node distance=2mm]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right=of n1] {saw\\VBD};
      \node (n3) [target, right=of n2] {a\\DT};
      \node (n4) [target, right=of n3] {girl\\NN};
      \node (n4') [target, right=of n4,draw=none,anchor=west] {};
      \node (n5') [target, below=5mm of n4',anchor=north,draw=none] {};
      \draw [thick,->] (n5'.center) -- ++(5mm,0);
    \end{tikzpicture}
    \caption{}
  \end{subfigure}
  \qquad\qquad
  \centering
  \begin{subfigure}[b]{0.4\textwidth}
    \begin{tikzpicture}[node distance=2mm]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right=of n1] {saw\\VBD};
      \node (nn) [notarget,draw=none,right=of n2] {};
      \node (n3) [target, right=of nn] {girl\\NN};
      \node (n4) [target, below=5mm of n3] {a\\DT};
      \draw [thick,->] (n4) -- (n3);
    \end{tikzpicture}
    \caption{}
  \end{subfigure}
\end{figure}

And the result: finish

UPDATE 2

Finally I've used gemot's solution:

\begin{figure}[ht]
  \centering
  \begin{tabular}{p{0.4\textwidth}cp{0.4\textwidth}}
    \begin{tikzpicture}[node distance=2mm,baseline=(n3)]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right=of n1] {saw\\VBD};
      \node (n3) [target, right=of n2] {a\\DT};
      \node (n4) [target, right=of n3] {girl\\NN};
    \end{tikzpicture}
  &
    \tikz\draw [thick,->] (0,0) -- ++(.5cm,0);
  &
    \begin{tikzpicture}[node distance=2mm,baseline=(n3)]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right=of n1] {saw\\VBD};
      \node (n3) [target, right=of n2] {a\\DT};
      \node (n4) [target, below=5mm of n3,anchor=north] {girl\\NN};
      \draw [thick,->] (n4) -- (n3);
    \end{tikzpicture}
  \\
    \subcaption{}
  &&
    \subcaption{}
  \end{tabular}
  \label{fig:rightaction}
\end{figure}

enter image description here

  • 1
    One way would be to use \tikzmark(many examples on this site) to mark an alignment point in the first picture and use that in the second picture to do the alignment. This will require two consiecutive runs of pdflatex. – Peter Grill Dec 8 '16 at 6:24
  • I am trying yo use tikzmark now, thanks, – ElBaulP Dec 8 '16 at 6:34
  • If you can't get it to work fully post how far you got and am sure someone here will help out. – Peter Grill Dec 8 '16 at 6:46
4

Here is a solution that does not require phantom drawings.

  • Use the baseline option of tikzpicture to specify the horizonal alignment.
  • Use some tabular environment for the overall arrangement. Because of the captions, you have to use p columns or some other type creating a box.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzset
  {common/.style =
    {rectangle, rounded corners, minimum width=1cm, minimum height=1cm,
     text centered, text opacity=1, align=center
    }
  ,notarget/.style = {common, draw=none, opacity=0}
  ,target/.style   = {common, draw=black, very thick}
  }

\begin{figure}[ht]
  \centering
  \begin{tabular}{p{0.4\textwidth}cp{0.4\textwidth}}
    \begin{tikzpicture}[node distance=1.2cm,baseline=(n3)]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right of=n1] {saw\\VBD};
      \node (n3) [target, right of=n2] {a\\DT};
      \node (n4) [target, right of=n3] {girl\\NN};
    \end{tikzpicture}
  &
    \tikz\draw [thick,->] (0,0) -- ++(1cm,0);
  &
    \begin{tikzpicture}[node distance=1.2cm,baseline=(n3)]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right of=n1] {saw\\VBD};
      \node (n3) [target, right of=n2] {a\\DT};
      \node (n4) [target, below of=n3,anchor=north] {girl\\NN};
      \draw [thick,->] (n4) -- (n3);
    \end{tikzpicture}
  \\
    \subcaption{before}
  &&
    \subcaption{after}
  \end{tabular}
  \caption{A transformation}\label{fig:rightaction}
\end{figure}
\end{document}
  • I am going to keep with this solution, thanks! – ElBaulP Dec 8 '16 at 11:40
4

There are probably lots of ways to do this. Two I can see easily implemented: (i) use a \savebox and \raisebox or (ii) do the same drawing, but invisible (with \path). I'll show only the second because I think it's considerably less complicated and, as far as I know, the \savebox/\raisebox solution is already in the site.

enter image description here

\documentclass{article}
\usepackage{tikz,calc}
\usepackage{subcaption}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}

\tikzset{notarget/.style={rectangle, rounded corners, minimum
  width=1cm, minimum height=1cm,text centered, draw=none,
  opacity=0,text opacity=1,align=center},
    target/.style={rectangle, rounded corners, minimum width=1cm, minimum
  height=1cm,text centered, draw=black, very thick,text
  opacity=1,align=center}}

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \begin{tikzpicture}[node distance=1.2cm]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right of=n1] {saw\\VBD};
      \node (n3) [target, right of=n2] {a\\DT};
      \node (n4) [target, right of=n3] {girl\\NN};
      \node (n4') [target, below of=n3,anchor=north,draw=none] {};% <<<<<<< INVISIBLE
      \path [thick,->] (n4) -- (n3);% <<<<<<<<<<< INVISIBLE
%      \draw [thick,->] (n4) -- ++(1cm,0);
    \end{tikzpicture}
    \caption{}
  \end{subfigure}
  \qquad\qquad
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \begin{tikzpicture}[node distance=1.2cm]
      \node (n1) [notarget] {I\\PRP};
      \node (n2) [notarget, right of=n1] {saw\\VBD};
      \node (n3) [target, right of=n2] {a\\DT};
      \node (n4) [target, below of=n3,anchor=north] {girl\\NN};
      \draw [thick,->] (n4) -- (n3);
    \end{tikzpicture}
    \caption{}
  \end{subfigure}
  \label{fig:rightaction}
\end{figure}
\end{document}

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.