0

I am using Tikzpicture to add a figure to my document, with the caption as a textbox inside a second node.

My text either extends beyond the page width, or becomes messy with uneven line widths. What to do?

I guess my problem originates from at least two different reasons:

  1. The lines inside the textbox extend beyond the borders of the page, see example below. But, when I change the text width from 30cm to, say, 10cm, then the textbox moves entirely to the right side, and it all goes out of the page. So I use 30cm (which is probably a problem) in order to align the start of the text to the left. But, now:
  2. If I try to fix it using line breakers in order to break the long lines, then their width is no longer equal.

I should not use line breakers, I know, but then what should I do instead?

Example:

 \documentclass[10pt,a4paper]{moderncv}
 \usepackage{tikz}
 \setlength{\hintscolumnwidth}{2.2cm}
 \begin{document}
     \begin{tikzpicture}[] 
         \node [anchor=north east]
        {\includegraphics[height=8cm]{SomePicture.png}}; 
        \node [below=9cm, align=left,text width=30cm] 
        {
           \footnotesize Yada yada, and some more text. This text has 
           two problems: 1. The lines 
           go beyond the borders of the page. 2. If I use \\ in order to 
           break \\ these \\ lines, then the line width is no longer 
           equal. \\ 
           How do I sort these two problems out? \\ 
           I should not use line breakers, I know, but then what should 
           I do instead? 
 };
 \end{tikzpicture} 
 \end{document}

Thanks!

5
  • please provide an example document not a fragment. Also size changes do not take an argument use \footnotesize ... not \footnotesize{...} Dec 5, 2022 at 16:43
  • If you want to use current page you need overlay. The inner sep=0cm at (current page.south) is wrong and you should get error messages in your log. You can use text width=\linewidthto get a node that fits the whole linewidth (or \textwidth). The second node is places 9cm below (0,0). What are you trying to do? How should it look like in the end? Dec 5, 2022 at 16:52
  • @ David and Qrrbrbirbel, Thank you, but please see the revised question, where I added the full document now. What do you think? Dec 5, 2022 at 16:54
  • @Qrrbrbirlbel I am trying to align the figure in the center, and the caption below it to the left, with equal line width in the text Dec 5, 2022 at 16:56
  • @Qrrbrbirlbel using text width=\linewidth pushes the whole captions node to the right, and it again slips beyond the page borders. Any idea why? And how to place it on the left, below the figure? --- Thanks again! Dec 5, 2022 at 17:14

1 Answer 1

2

The text is placed below the figure, with a width equal to that of the figure.

The width of the Pic node containing the figure is the distance between its west and east anchors.

To this end, the coordinates of a point \p1 are calculated by subtracting Pic.east from Pic.west. The width of the Pic node can be obtained from its x-coordinate (\x1).

Using text width=\x1 the line break is done automatically.

a

\documentclass[10pt,a4paper]{moderncv}

\firstname{FirstName}% needed for modercv
\familyname{LastName}% needed for modercv

\usepackage{tikz}
\usetikzlibrary{positioning}% added <<<<<<<<<<
\usetikzlibrary{calc}% added <<<<<<<<<<
    
\begin{document}    

\begin{tikzpicture}
    \node[inner sep=0pt] (Pic)  {\includegraphics[height=8cm]{example-image-a.jpg}};
    
    \path let \p1=($(Pic.east)-(Pic.west)$) in  node[
      below= 0.5cm of Pic.south, 
      anchor = north,
      inner sep=0pt, 
      text width= \x1, 
      font =\footnotesize] {Yada yada, and some more text. This text has two problems: 1. The lines go beyond the borders of the page. 2. If I use  in order to break  these  lines, then the line width is no longer equal.    How do I sort these two problems out?   I should not use line breakers, I know, but then what should    I do instead? };    
\end{tikzpicture}
    
\end{document}

In the example the "caption" is centered with the figure. Its is possible to use text width= \x1-<lenght> to add left and right margins.

1
  • Wonderful. Thanks a lot! Dec 5, 2022 at 22:10

You must log in to answer this question.

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