12

Is there some command to wrap around an element \unknown{<element>} that gives a way to place an element, say, 5cm above where it would be placed without the unknown wrapper, even if it overlaps something as a result.

Basically, a command that pushes an element 5cm up in any scenario.

My particular use case is that I want to add an x-label to a graph after-the-fact.

1
  • If you tell us how you do your graph we can give more specific solutions. Shifting the position inside a, say, tikzpicture can be done using dedicated commands. Jan 24, 2012 at 10:07

2 Answers 2

13

You can raise the text using \raisebox{<amount>}[<set height>][<set depth>]{<content>} and also change its official height and depth. The original dimensions are available as \height, \depth, \totalheight (height+depth) and \width.

So \raisebox{5cm}[\height][\depth]{<some content>} should move it 5cm up, but keep the original dimensions as they are, making LaTeX think the content didn't change.

3
  • What about moving it horizontally? If you wanted to move it 5cm up and then 3cm right/left, what would that be? I tried several combinations but nothing worked.
    – Alenanno
    May 24, 2012 at 13:06
  • 1
    @Alenanno: Note that normally you don't move text around like this in a proper document. It's not a website etc. You might want to use a tikzpicture instead. Inside normal text you can however use the adjustbox package, it give you \adjustbox{<key=value,...>}{<content>} with a raise key identical to \raise and a lap key which allows you to move text horizontally. Check the manual for more details. If you have problems feel free to post a new question which links back to this one and includes an example text. May 24, 2012 at 13:11
  • I actually used the adjustbox already, I totally forgot about it... Thank you. By the way, I wasn't moving text but a custom element.
    – Alenanno
    May 24, 2012 at 13:30
2

There are several ways:

For the more complex examples, you can use the following:

\setlength{\unitlength}{1cm}
\begin{picture}(0,0) % make a drawing area that takes no place
  \put(5,3){Still, you can put this text 5 cm right and 3 cm above}
  \put(0,0){And another one, placed at the "original point", but occupying no space}
\end{picture}

If you want it to occupy its place in horizontal, but to move vertially, you can use

\strut% ensures that the line has the correct height
\smash{% smashes its content verically
  \raise 5cm% move the following box 5 cm up
    \hbox{% horizontal contents
      Foo bar}}

And you can omit all the % and newlines and say just

\strut\smash{\raise 5cm\hbox{Foo bar}}
2
  • Aren't the last two example different? In one you have the equivalent of \hbox{ Foo... and the last one is \hbox{Foo... (leading space deleted?). Jan 24, 2012 at 17:27
  • Yes, sorry, there should be no space before the percent-sign, corrected.
    – yo'
    Jan 24, 2012 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .