2

How can I get a linebreak inside a \put?

\documentclass{article}
\usepackage[percent]{overpic}

\begin{document}
\begin{overpic}[width=0.5\textwidth,grid,tics=10]{pictures/baum}
 \put (20,50) {first line text \newline \linebreak[4]

second line text}
\end{overpic}
\end{document}

When I complie it like that "first line text second line text" is written in one line :(

I adapted the minimum example from https://tex.stackexchange.com/a/20802/128042

Jakob
  • 993
  • For instance a tabular works: `\documentclass{article} \usepackage[percent]{overpic}

    \begin{document} \begin{overpic}[width=0.5\textwidth,grid,tics=10]{example-image-duck} \put (20,50) {\begin{tabular}{l} first line text\ second line text \end{tabular}} \end{overpic} \end{document}`

    –  Sep 07 '19 at 17:22
  • Or parbox: `\documentclass{article} \usepackage[percent]{overpic}

    \begin{document} \begin{overpic}[width=0.5\textwidth,grid,tics=10]{baum} \put (20,50) {\parbox{3cm}{first line text \ second line text}} \end{overpic} \end{document}`

    – Vladimir Sep 07 '19 at 17:29

2 Answers2

3

You can use minipage, with a big enough width, since you're specifying the line breaks.

\documentclass{article}
\usepackage[percent]{overpic}

\begin{document}
\begin{overpic}[width=0.5\textwidth,grid,tics=10]{example-image}
 \put (20,50) {\begin{minipage}{\textwidth}first line text\\second line text\end{minipage}}
\end{overpic}

\bigskip

\begin{overpic}[width=0.5\textwidth,grid,tics=10]{example-image}
 \put (20,50) {\begin{minipage}[t]{\textwidth}first line text\\second line text\end{minipage}}
\end{overpic}

\bigskip

\begin{overpic}[width=0.5\textwidth,grid,tics=10]{example-image}
 \put (20,50) {\begin{minipage}[b]{\textwidth}first line text\\second line text\end{minipage}}
\end{overpic}

\end{document}

Note that the placement (20,50) refers to the reference point of the minipage: centered between top and bottom with no optional argument, the baseline of the top line with [t] and the baseline of the bottom line with [b].

enter image description here

You could also do

\begin{tabular}{@{}l@{}}first line text\\second line text\end{tabular}`

or with \begin{tabular}[t]{@{}l@{}} or \begin{tabular}[b]{@{}l@{}} to the same effect.

egreg
  • 1,121,712
  • For the 2nd image there is a fake overlapping of the sequence of numbers from 0 to 100 with the third image. However, my vote remains positive. – Sebastiano Sep 07 '19 at 19:58
  • @Sebastiano Oh, that's just that the guide numbers don't take vertical space, so \bigskip between the image is not sufficient; the numbers and the grid will disappear anyway in the production version, because they're used just for helping in placement of the objects. – egreg Sep 07 '19 at 20:20
  • Always remember that I am a low user even in English language :O) – Sebastiano Sep 07 '19 at 20:27
2

You could use a tabular environment, but the code is shorter with \eqparbox:

\documentclass{article}
\usepackage[percent]{overpic}
\usepackage{eqparbox}
\usepackage{xcolor}

\begin{document}

\begin{overpic}[width=0.5\textwidth,grid,tics=10]{example-image}%{pictures/baum}
 \put (20,50) {\eqparbox{OP}{\sffamily\large\color{red}first line text \\ second line text}}
\end{overpic}

\end{document} 

enter image description here

Bernard
  • 271,350