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.

The following code mis-renders the multi-line label:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
\begin{tikzpicture}
\node (A) at (0,0) {A};
\node (B) at (0,2) {B};
\draw (A) to node [anchor=east, align=right] {my\\multi-line\\label} (B);
\end{tikzpicture}
\end{aligned}
\end{equation}
\end{document} 

It's all the fault of the aligned environment - which, however, is necessary to get the equation number to typeset in the proper place with respect to the diagram.

So: is this a weird interaction bug? Can it be solved? Or is there a hack that just lets me align my picture using a different method to avoid this strange issue? Or perhaps my TikZ is buggy, or this isn't the correct way to do multi-line labels.

Screenshot with code as above: screenshot with code as given

Screenshot without aligned environment: screenshot without aligned environment

share|improve this question
    
Do you have a complete MWE of "the equation" you mention? I'm pretty sure it can be resolved without "blaming" the aligned environment. :) –  Werner Dec 9 '11 at 19:19
    
Using split instead of aligned seems to help, but the line spacing is a little different. –  Torbjørn T. Dec 9 '11 at 19:20
    
An image which shows the incorrect behavior would also be very good. –  Martin Scharrer Dec 9 '11 at 19:23
    
Hi Werner - I've given a MWE in the question! Typeset it with and without the aligned environment and you'll see what I mean. –  Jamie Vicary Dec 9 '11 at 19:24
2  
If the only thing that you use the aligned environment for is the numbering, you could take a look at tex.stackexchange.com/q/14599/86 which provides a pure TikZ way of putting in equation numbers (the code is at bazaar.launchpad.net/~tex-sx/tex-sx/development/files as tikzeqnos.tex but as the file extension suggests, I haven't worked on it much since the original code. My converting-answers-to-packages time recently has been taken up with some random knot package. Maybe I should switch to the equation number one for a while ...) –  Andrew Stacey Dec 9 '11 at 21:18
show 2 more comments

3 Answers

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
\tabular{r|} \multicolumn{1}{r@{}}{\makebox[0pt]{A}}\\
  my \\ multi-line \\ label \\
             \multicolumn{1}{r@{}}{\makebox[0pt]{B}} 
\endtabular
\end{align}

\end{document} 

enter image description here

share|improve this answer
add comment

Just change aligned into gathered:

\begin{equation}
\begin{gathered}
\begin{tikzpicture}
\node (A) at (0,0) {A};
\node (B) at (0,2) {B};
\draw (A) to node [anchor=east, align=right] {my\\multi-line\\label} (B);
\end{tikzpicture}
\end{gathered}
\end{equation}

enter image description here

Actually, gathered (as well as aligned) changes the line spacing, so maybe you'll prefer to use a gathered* environmen defined as

\newenvironment{gathered*}{\gathered\openup-1\jot}{\endgathered}

Actually, a simpler solution might be to say

\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node (A) at (0,0) {A};
\node (B) at (0,2) {B};
\draw (A) to node [anchor=east, align=right] {my\\multi-line\\label} (B);
\end{tikzpicture}
\end{equation}
share|improve this answer
    
This is the simplest solution, so I like it the most - but it affects the line spacing! –  Jamie Vicary Dec 9 '11 at 23:23
    
@JamieVicary Just like aligned. I'll add a workaround. –  egreg Dec 9 '11 at 23:25
add comment

Would "boxing" the "my multiline label" work? Boxing here refers to placing the contents in a tabular.

enter image description here

\documentclass{article}
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{equation}
\begin{aligned}
\begin{tikzpicture}
\node (A) at (0,0) {A};
\node (B) at (0,5) {B};
\draw (A) to node [anchor=east] {\begin{tabular}{r@{}}my\\[\jot]multi-line\\[\jot]label\end{tabular}} (B);
\end{tikzpicture}
\end{aligned}
\end{equation}
\end{document}

Using a r@{} column specification for the tabular removes the column separation on the right, providing a similar alignment as obtained with align=right. \\[\jot] spreads out the tabular lines, similar to renewing \arraystretch, but allows for line-by-line control. Use it if needed.

share|improve this answer
    
The boxing isn't necessary, you could just put the tabular directly in the node. –  Torbjørn T. Dec 9 '11 at 19:36
    
@TorbjørnT.: Thanks for the suggestion... –  Werner Dec 9 '11 at 19:53
add comment

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.