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 would like the following TikZ qtree to come out symmetric:

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\Tree[.O [.N O R ] [.O N \fbox R ] [.R N O ]]
\end{document}

(so that, in particular, the edge from the root to its child 'O' is vertical). Since

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\Tree[.O [.N O R ] [.O N R ] [.R N O ]]
\end{document}

is symmetric, obviously it's the \fbox that's preventing this; so I thought that something like:

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\Tree[.O [.N O R ] [.O N {\smash{\fbox R}\phantom R} ] [.R N O ]]
\end{document}

would work, but it seems actually to be worse. (I think that this doesn't really have anything to do with qtree, which is why I didn't put it in the tags, but I couldn't think up an equivalent example without it.)

(EDIT: Per @DavidCarlisle's advice, I made all code snippets compile-able.)

share|improve this question
1  
please always post complete documents not fragments that can't be run without effort, but \smash only hides the height not the width so \smash{\fbox R}\phantom R is more than twice as wide as R you may prefer \frame{R} to \fbox{R} –  David Carlisle Feb 4 at 21:20
    
@DavidCarlisle, thanks for the advice. (a) The three code samples are now complete documents. (b) Oops, my mistake; but is there a command that hides height and width? (c) Why would I prefer \frame? –  L Spice Feb 4 at 21:32
    
Gonzalo's given an answer but I for example didn't recognise the package so I wouldn't have been able to test the example, although I could otherwise answer the hiding width question. I just offered \frame as an alternative as it is not so often seen but it is a variant of fbox that doesn't add the extra width. –  David Carlisle Feb 4 at 21:38
    
@DavidCarlisle, thanks. I'm looking for something with the same visual appearance as \fbox R (which \frame R doesn't seem to be), but that is perceived by TeX as having the height and width of an undecorated R. I did see Gonzalo's answer, which accomplishes the effect that I want; but is there any general command that forces a box to be treated as having 0 height and width? –  L Spice Feb 4 at 21:41
2  
\makebox(0,0){foo} (the round bracket form is mainly used in picture environment but works generally and allows specification of height and depth, to 0 here) –  David Carlisle Feb 4 at 21:43
show 2 more comments

1 Answer 1

up vote 5 down vote accepted

You can trick TeX to see only a box of the width of the boxed character:

\documentclass{article}
\usepackage{tikz-qtree}
\usepackage{calc}

\begin{document}

\Tree[.O [.N O R ] [.O N \makebox[\widthof{R}][c]{\fbox{R}} ] [.R N O ]]

\end{document}

enter image description here

share|improve this answer
    
Thank you for this solution. Is there, more generally, any way to convince TeX that a box has zero height and <strike>depth</strike> width? (I was simply blindly believing this answer, which either I misunderstood or is incorrect.) (EDIT: I now see that I have been using depth' when I meant width'.) –  L Spice Feb 4 at 21:33
    
@LSpice You're welcome. Notice that the box won't have zero width; it will have a width equal to the width of "R". –  Gonzalo Medina Feb 4 at 22:00
    
Indeed, I noticed that it thus bypasses the need for the extra \phantom R. I was wondering (in my comments to David Carlisle in the original question) if I could avoid the dependence on calc, but, as I think about it more, why bother? –  L Spice Feb 4 at 22:14
1  
@LSpice Have a look at \rlap, \clap, \llap, \mathrlap, \mathclap and \mathllap from \usepackage{mathtools}. –  tohecz Feb 4 at 23:34
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.