Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want two text blocks in a horizontal row. In the middle between them, there should be an arrow pointing from left to right.

This is what I currently have:

enter image description here

As you see, the arrow is not in the middle between the two text blocks. That's something I want to achieve.

Right now I'm using minipages with fixed width to achieve the result above.

\begin{minipage}{.2\textwidth}
\begin{verbatim}
X := 3
Y := Z * W
Q := X + Y
\end{verbatim}
\end{minipage}
%
\begin{minipage}{.2\textwidth}
  \centering $\Rightarrow$
\end{minipage}
%
\begin{minipage}{.2\textwidth}
\begin{verbatim}
X := 3
Y := Z * W
Q := 3 + Y
\end{verbatim}
\end{minipage}

But with that solution I would have to adjust the absolute width of the minipages until the text fits inside. That's not a clean solution though, because when I change the text size (or anything else related to the font) everything will break.

Is there a clean solution to horizontally align the two text blocks, with an arrow in the middle between them, and with adjustable whitespace between the blocks and the arrow?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Use \hfill:

\documentclass{article}
\begin{document}
\begin{minipage}{.2\textwidth}
\begin{verbatim}
X := 3
Y := Z * W
Q := X + Y
\end{verbatim}
\end{minipage}
\hfill $\Rightarrow$ \hfill
\begin{minipage}{.2\textwidth}
\begin{verbatim}
X := 3
Y := Z * W
Q := 3 + Y
\end{verbatim}
\end{minipage}
\end{document}

Note that the arrow seem not centered because the space not filled in minipages. For a better results you can use varwidth package instead of minipage

\documentclass{article}
\usepackage{varwidth}
\begin{document}
\hfill
\begin{varwidth}{.2\textwidth}
\begin{verbatim}
X := 3
Y := Z * W
Q := X + Y
\end{verbatim}
\end{varwidth}%
\hfill$\Rightarrow$\hfill%
\begin{varwidth}{.2\textwidth}
\begin{verbatim}
X := 3
Y := Z * W
Q := X + Y
\end{verbatim}
\end{varwidth}
\hfill
\end{document}

Using \dotfill instead of \hfill you can check visually that both block are reaally equally spaced.

MWE

Note: Be careful of remove spaces around \hfill (thanks to David to note the lack of ending %).

share|improve this answer
    
Thanks, but that doesn't really solve the problem. If I use {.4\textwidth} as width for the blocks, the arrow is not centered at all. –  Danilo Bargen Sep 7 '13 at 10:25
    
@DaniloBargen, please see the edited answer. –  Fran Sep 7 '13 at 10:32
    
The OP wanted it centred on the longest lines of the text, but note this does not center between the minipages either, the space to the left of the arrow is one word space (3.333pt) more than the space to the right as you are missing a % after \end{minipage} –  David Carlisle Sep 7 '13 at 10:34
    
@DavidCarlisle, I always forget the ending %. Thanks for the advice. –  Fran Sep 7 '13 at 10:48
    
Thanks for the edit! Works great now. And with using \hspace instead of \hfill I can control the exact space between the arrow and the blocks. –  Danilo Bargen Sep 7 '13 at 10:49

Please always post complete documents, not just fragments.

enter image description here

If a minipage contains tabbing it is just as wide as the widest tabbing row. Don't forget the %

\documentclass{article}

\begin{document}

\begin{minipage}{.2\textwidth}\ttfamily
\begin{tabbing}
X := 3\\
Y := Z * W\\
Q := X + Y
\end{tabbing}
\end{minipage}%
\hfill $\Rightarrow$\hfill
\begin{minipage}{.2\textwidth}\ttfamily
\begin{tabbing}
X := 3\\
Y := Z * W\\
Q := 3 + Y
\end{tabbing}
\end{minipage}

\end{document}
share|improve this answer
    
With {\centering\hfill<your stuff>\hfill\null\par} the thing is less spread out on the line. –  jfbu Sep 7 '13 at 10:41
    
it is not in my testing... another point: rather than \hfill$\Rightarrow$\hfill a \makebox or minipage as in OP allows user control on the inner spaces. And then \centering suffices with no \hfill's. –  jfbu Sep 7 '13 at 10:48
    
@jfbu I can also control the inner space by using \hspace instead of \hfill. @David Carisle: Yes, I'll try to post complete examples next time :) –  Danilo Bargen Sep 7 '13 at 10:49
    
@DaniloBargen right, but with a \makebox you control better the positions of the left and right blocks on the line as you don't have to estimate the width of the right arrow. –  jfbu Sep 7 '13 at 10:52
    
@jfbu: Yes, true. –  Danilo Bargen Sep 7 '13 at 10:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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