4

I'm trying to create a tikz picture where I have an image with some text to the right of it. Between the image and the text I want to draw a vertical line that is the same distance away from the edge of the image as from the edge of the text. See the included picture.

1

Currently I have the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

\node[inner sep=0pt] (image) at (0,0)
    {\includegraphics[width=.25\textwidth]{example-image-a}};
    
\node[anchor = west ,xshift=0cm, yshift=0, text width = 0.5\textwidth, right = of image]{\Huge Text};

\draw[line width=1mm](2.25,-1) -- +(0,2); 

\end{tikzpicture}
\end{document}

Important to note is that I would prefer an exact solution, not an estimation like I did by having the line at x=2.25 within the tikz picture (which 'looks' right). I would like a solution that dynamically changes location when the images is moved (the text already moves dynamically with the picture using right=of image).

0

1 Answer 1

5

You can use the calc library:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}
\begin{tikzpicture}

\node[inner sep=0pt] (image) at (0,0)
    {\includegraphics[width=.25\textwidth]{example-image-a}};
    
\node[anchor=west,right=of image,inner sep=0pt] (text) {\Huge Text};

\draw[line width=1mm] ($(image.east)!0.5!(text.west)$) +(0,-1) -- +(0,1);

\end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    Lovely, works like a charm! I tried to use the calc package, bit did not now you could use .west and .east to get the edges of nodes, thank you! Apr 18, 2022 at 19:07

You must log in to answer this question.

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