I am using the overpic package to place text inside of a figure.
For using line breaks inside a put
command I use parbox
(see example code).
\documentclass{article}
\usepackage{graphicx}
\usepackage[percent]{overpic}
\begin{document}
\begin{figure}[h!]
\centering
\begin{overpic}[width=0.3\textwidth]{example-image}
\put(56,47){\parbox{10cm}{some\newline too long text}}
\end{overpic}
\end{figure}
\end{document}
Using this code, the text is aligned left at the specified position of the put
command.
How can I center the text around the specified position in the put
command so that in the example code "some" should appear somewhere above "long"? Note that using centering
centers the text around the middle of the figure which is not what I want.
Best Answer
Your questions seems to have 2 components to it:
Centering the various lines of text relative to each other, and
Centering the block of text relative to the
\put
position.For #1, I choose to use a stack, which also helps with #2, where I place the stack in a zero-width
\makebox
.The MWE, where I also place a red dot at the same location, so that we can see that these
\put
s are centered about the\put
point.I might also suggest the alternative of using a
\stackinset
instead of anoverpic
. The horizontal alignment ofl
,c
,r
(argument 1) and the vertical alignment oft
,c
,b
(argument 3) non only tell where on the background image to use as the alignment reference, but also where on the inset to use as the reference. Thus the use ofc
for both of these will guarantee that the center of the inset is placed relative to the center of the image, at the offsets provided.