1

I have the following two-column article, where I am resizing 3 TikZ figures inside subfigures as to fit them in a single column (code below).

enter image description here

I want all the text in the TikZ figures (in this specific case, the As and Bs inside the squares) to match the font size of the document (that is, the TikZ font size to be equal to the Lorem ipsum font size).

How can I ensure this after resizing?

How can the text in a TikZ figure be forced to match the text size of a document?

\documentclass[12pt,twocolumn]{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\usepackage{circuitikz}

\usepackage[hypcap=true]{subcaption}

\begin{document}

\begin{figure}[!h]
    \centering
    \begin{subfigure}[b]{0.33\columnwidth}
        \centering
        \resizebox{\columnwidth}{!}{%
\begin{tikzpicture}[box/.style={draw, thick, minimum size=10mm}]
    \node [box] (A) {A};
    \node [box, right=20mm of A] (B) {B};
    \path (A) to [lowpass, name=lpf] (B);
    \draw [-{Latex[length=2mm]}] (A.east) to (lpf.west);
    \draw [-{Latex[length=2mm]}] (lpf.east) to (B.west);
\end{tikzpicture}
        }
        \caption{}
    \end{subfigure}%
    \begin{subfigure}[b]{0.33\columnwidth}
        \centering
        \resizebox{\columnwidth}{!}{%
\begin{tikzpicture}[box/.style={draw, thick, minimum size=10mm}]
    \node [box] (A) {A};
    \node [box, right=20mm of A] (B) {B};
    \path (A) to [lowpass, name=lpf] (B);
    \draw [-{Latex[length=2mm]}] (A.east) to (lpf.west);
    \draw [-{Latex[length=2mm]}] (lpf.east) to (B.west);
\end{tikzpicture}
        }
        \caption{}
    \end{subfigure}%
    \begin{subfigure}[b]{0.33\columnwidth}
        \centering
        \resizebox{\columnwidth}{!}{%
\begin{tikzpicture}[box/.style={draw, thick, minimum size=10mm}]
    \node [box] (A) {A};
    \node [box, right=20mm of A] (B) {B};
    \path (A) to [lowpass, name=lpf] (B);
    \draw [-{Latex[length=2mm]}] (A.east) to (lpf.west);
    \draw [-{Latex[length=2mm]}] (lpf.east) to (B.west);
\end{tikzpicture}       
        }
        \caption{}
    \end{subfigure}
\end{figure}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis laoreet, quam quis tristique hendrerit, neque massa sagittis ante, ac interdum ante nisi in diam. Nunc purus ante, luctus vitae eleifend a, euismod et urna. Suspendisse potenti. Sed accumsan hendrerit enim, eu fermentum orci lacinia non. Sed dignissim nisl diam, at sagittis mi faucibus in. Donec mauris massa, sollicitudin maximus ullamcorper eu, dapibus eget ex. Nulla bibendum vel lectus non ullamcorper. Vivamus cursus nunc sed imperdiet sodales. Mauris tristique leo ligula, id pretium massa congue eget. Mauris est dolor, cursus vitae augue vitae, tempus commodo turpis. Etiam vel leo nec ligula mollis iaculis vel ac augue. Praesent libero augue, ultrices ac gravida eget, rhoncus in neque. Aliquam sit amet ultrices ipsum, a commodo erat. Quisque eu ante libero. Etiam sit amet malesuada purus.

Praesent eget mollis augue. Integer vehicula sem eget ipsum congue, in tincidunt lacus pharetra. Nam tincidunt turpis in molestie laoreet. Nullam mattis, enim vitae volutpat molestie, lacus tellus tempor dui, et scelerisque urna metus a tellus. In id orci in metus feugiat tempor. Etiam vel diam eu neque rutrum venenatis et vel erat. Proin varius placerat ullamcorper. Praesent sapien ligula, semper et ultricies vel, tristique sit amet lacus. Etiam porta leo diam, nec consectetur nulla elementum eu. Nullam in venenatis ipsum. Nunc elit turpis, imperdiet vel neque a, maximus elementum orci. Nam pellentesque arcu id sem finibus ultrices. Etiam hendrerit lacus non felis hendrerit, in aliquam mi euismod. Sed ac egestas diam, a ultrices nisl.

Mauris odio felis, venenatis id lorem ac, consectetur gravida nunc. Etiam consequat sem at gravida tempus. Nam et eros aliquet, tristique lacus et, mollis mi. Morbi quam felis, maximus nec feugiat a, egestas in erat. Donec mattis ipsum vel bibendum ultricies. In in ipsum erat. Morbi dignissim ultricies nunc, viverra iaculis metus laoreet at. Morbi fringilla bibendum posuere. Quisque nisl risus, porta fermentum leo auctor, consequat laoreet velit.

Vivamus in neque vulputate neque facilisis pellentesque. Fusce id varius libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean vitae mauris nisl. Curabitur lacinia est vitae cursus dignissim. Vestibulum luctus neque nec libero molestie, a tempus nunc cursus. Curabitur nec nunc eros. Nullam sed pharetra ligula, eget volutpat nunc. Pellentesque non nunc vel metus fringilla efficitur. Mauris quis luctus justo. In vel erat in magna eleifend scelerisque vel consequat tellus. Cras ornare arcu vel dui aliquet, tristique efficitur mi dapibus. Nulla in tincidunt justo. Sed tortor tellus, congue vel dapibus ac, tincidunt eu quam. Donec laoreet neque eu suscipit tempor.

Integer consectetur nunc ac eros malesuada, eget dapibus nunc laoreet. Cras vel nisl ante. Fusce metus purus, malesuada in pretium quis, eleifend a mi. Fusce lobortis nisl enim, at laoreet est sodales a. Pellentesque egestas condimentum urna. Ut porta eget felis vitae semper. Praesent varius ligula efficitur sollicitudin tempor.


\end{document}
  • How to use \resizebox but not resize text (tikzpicture) seems to be related so you might find a useful answer there. – leandriis Feb 4 '18 at 10:09
  • don't use \resizebox :-) . you should find another way to fit your images in line. – Zarko Feb 4 '18 at 10:09
  • 1
    Using \begin{tikzpicture}[scale=...] should keep font size and line width while scaling node distances. – Jasper Habicht Feb 4 '18 at 10:26
  • @JasperHabicht, scale= in op case doesn't work (due to used circuitikz element lowpass. – Zarko Feb 4 '18 at 11:05
  • You realize that most of the nodes get their size from the text inside (plus inner sep). They can't shrink without also shrinking the text. – John Kormylo Feb 4 '18 at 16:30
3

like this?

enter image description here

instead of images you need to reduce nodes size and distance between them. node from circuitikz should be scaled. appropriate scale factor i found by "trial and error". in mwe below also the code for images is slightly simplified.

\documentclass[12pt,twocolumn]{article}
\usepackage{circuitikz}
\usetikzlibrary{arrows.meta, positioning}
\usepackage[hypcap=true]{subcaption}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
    \begin{figure}[htb]
\tikzset{box/.style = {draw, thick, inner sep=2pt, minimum size=6mm},
          LA/.style = {-{Latex[length=2mm]}},
      node distance = 13mm
       }
\ctikzset{bipoles/length=9mm}
\centering
    \begin{subfigure}[b]{0.32\linewidth}
        \centering
\begin{tikzpicture}
    \node [box] (A) {A};
    \node [box, right=of A] (B) {B};
    \path (A) to [lowpass, name=lpf] (B);
    \draw [LA] (A) to (lpf.west);
    \draw [LA] (lpf.east) to (B);
\end{tikzpicture}
        \caption{}
    \end{subfigure}
\hfill
    \begin{subfigure}[b]{0.32\linewidth}
        \centering
\begin{tikzpicture}
    \node [box] (A) {A};
    \node [box, right=of A] (B) {B};
    \path (A) to [lowpass, name=lpf] (B);
    \draw [LA] (A) to (lpf.west);
    \draw [LA] (lpf.east) to (B);
\end{tikzpicture}
        \caption{}
    \end{subfigure}
\hfill
    \begin{subfigure}[b]{0.32\linewidth}
        \centering
\begin{tikzpicture}
    \node [box] (A) {A};
    \node [box, right=of A] (B) {B};
    \path (A) to [lowpass, name=lpf] (B);
    \draw [LA] (A) to (lpf.west);
    \draw [LA] (lpf.east) to (B);
\end{tikzpicture}
        \caption{}
    \end{subfigure}
\end{figure}
\lipsum[2-4]
\end{document}

note:

your problem arise from mixing elements from two different packages: tikzpicture and tikz which has different approach to scaling their elements (as far as i know). so you have three possibilities to managed your problem:

  • use solution showed above
  • use image in its natural size and put each sub images in own line
  • span figure float over both column, i.e. instead {figure} use {figure*}. however it can be placed only on the top of the next page or in the case, that you employ package stfloats on the bottom of the same page, where it is inserted.

of course, you can stick with your method and accept the fact that with use of \resizebox font size shrink too.

  • Isn't it possible to scale the figure directly leaving the font size anchored? – erik Feb 4 '18 at 17:14
  • @tli, try this, but before read comments below your question. – Zarko Feb 4 '18 at 17:15
  • What you propose is a good solution, the problem is that I am looking for a more general method where no matter what text in a tikz picture, its size is anchored and everything else is scaled – erik Feb 4 '18 at 17:59
  • @tli, well then don't scale your images at all. use them as they have natural size, for example in your case as three subimages each below other, or span figure over both column of text. there is not general method to put elephant into suitcase :-) (for this some wizardry had to be employed ...). or stick with your method and accept the fact that in this case font size shrink too. – Zarko Feb 4 '18 at 18:10
  • Okay, let's say that I want an image to span half of the column width of a document, but then want the TikZ font size to be equal to the text font size. Then, since the nodes stay as big as they were before, I would like the nodes and distances to be re-adjusted automatically. Isn't there a way to do this programatically instead of by "trial and error"? Otherwise, your solution is great – erik Feb 4 '18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.