1

I'm trying to place two TikZ figures next to each other, scaling them to half a page each. I'm currently doing it with \subfigure[t]{.5\linewidth} and \resizebox{\linewidth}{!}{}. The latter is something I found in another script and don't fully understand, more the fact that I rescale my figure. Anyhow, the second figure becomes a few small black lines. I have no idea why, and searching didn't give me any better clue. Anyone knows where I have gone wrong? Sorry for a not so minimal MWE.

\documentclass[twocolumn, 10pt]{extarticle}
  \usepackage[utf8]{inputenc}
  \usepackage[english]{babel}
  \usepackage{csquotes}
  \usepackage[T1]{fontenc}
  \usepackage{amsmath}
  \usepackage[hypcap = true]{subcaption}
  \usepackage{tikz}
  \usetikzlibrary{shapes.geometric, positioning, automata, arrows, calc}

  \begin{document}
  \begin{figure*}[!hbtp]
    \tikzstyle{square}=[rectangle,thick,minimum size=0.5cm,draw=black!100,fill=blue!20]
    \begin{subfigure}[t]{.5\linewidth}
    \centering
    \resizebox{\linewidth}{!}{
        \begin{tikzpicture}[auto, outer sep=3pt, node distance=2cm,>=latex']
        \node [square, text width = .8\textwidth] (Draw) {LalaLal aLalaLal aLalaL alaLalaLalaLal aLalaLala LalaLala};           
        \node [square, below = 15mm of Draw, text width = .7\textwidth] (Matrix) {LalaLala LalaL alaLalaLalaLa laLa laLalaL alaLa laLal aLalaLala LalaL alaLal aLala};              
        \node [square, below = 12mm of Matrix] (TrialMatrix) {Experiment matrix of a subset of the trial points.};              
        \node [square, below = 15mm of TrialMatrix] (TrialPoint) {La laL al aLala Lala LalaL alaLa laLalaLalaLal aLalaLala};            
        \node [square, below = 10mm of TrialPoint] (Pnew) {LalaLalaL ala LalaL alaLal aLala LalaLa laL alaL ala Lala };             
        \node [below = 20mm of Pnew] (LogicGate) {};            
        \node [square, right = 30mm of LogicGate] (Penalty) {LalaLalaLa laLal aLalaLa laLal aLa laLala};            
        \node [square, below = 10mm of Penalty,fill=red!20] (PenaltyEnd) {LalaLalaLala};            
        \node [square, left = 15mm of LogicGate,text width = .6\textwidth] (Replace) {RLa laLalaLal aLala LalaLa laLal aLal aLala};             
        \node [square, below = 10mm of LogicGate,text width = .6\textwidth] (Criteria) {Lala LalaLala LalaLa la};           
        \draw [thick,->] (Draw.south) to node [above left] {Lal aLa laLa la Lal aLa la Lala } node [above right] {fLala La laLa laLala} node [left] {Lal aL ala LalaLal a} node [right] { Lala Lala Lala Lala} node [below left] {} node [below right] {} (Matrix.north);           
        \draw [thick,->] (Matrix.south) to node [left] {La laL ala LalaL al aLa la} node [right] {LalaL alaLa la Lala} node [below left] {Lala Lal aL alaLa la} node [below right] {Lal aLala Lala} (TrialMatrix.north);            
        \draw [thick,->] (TrialMatrix.south) to node [above left] {Lala LalaLa laLal aLala} node[above right] {LalaL alaLal aLalaLal aLalaL alaL ala La laLal a} node [left] {LalaL alaLal aLalaLal aLalaLal aLalaL alaLalaLa laLalaLa laLala} node [right] {La laL alaLalaL alaLalaL alaLalaLal aLalaL alaLala } node [below left] {La laLalaLa laLalaLa laLalaL alaLal aLala} node [below right] {random trial point. $P_{new}=2{\times}\overline{P}-P_{r}$}(TrialPoint.north);           
        \draw [thick, ->] (TrialPoint.south) -- node [left] {La la LalaLa l aLal aLa laLal aLala} node [right] {La laLal aLal aLala Lala Lala Lala} (Pnew.north);            
        \draw [thick,->] (Pnew.south) -- node [above left] {LalaL alaLal aLala LalaL alaLala} node [above right] {La laLala LalaLala} node [left] {LalaL a laL alaL ala} node [right] { Lala Lal aLala } node [below left] {Lal aLa laLala} node [below right] {La laL alaLala.} (LogicGate);           
        \draw [thick,->] (LogicGate) -- node [below] {LalaLala} (Penalty);              
        \draw [thick,->] (LogicGate) -- node [below] {} (Criteria);             
        \draw [thick,->] (LogicGate) -- node [below] {Lala Lala Lala} (Replace);            
        \draw [thick,->] (Penalty) -- node[left] {Lala} node [right] {LalaLalaLala} (PenaltyEnd);      
        \draw [thick,->] (Penalty.east) -- ($(Penalty.east) - (-.3,0)$) |- node [below left] {La Lalalala} (Matrix.east);           
        \draw [thick,->] (Criteria.west) -- node [above] {Lala} ($(Criteria.west) - (4.6,0)$) |- (Matrix.west);             
        \draw [thick,->] (Criteria.east) -- node [above] {Lqlq} (PenaltyEnd.west);              
        \end{tikzpicture}
        }
        \caption{Lala
        }\label{LalaLala}
    \end{subfigure}
  ~
    \begin{subfigure}[t]{.5\linewidth}
    \centering
    \resizebox{\linewidth}{!}{
        \begin{tikzpicture}[auto, outer sep=3pt, node distance=2cm,>=latex']            
        \node [square](CRS12) {Lala LalaLalaLala Lala};             
        \node [square, right = 30mm of CRS12] (CRS22) {LalaL alaLalaLalaLa laLalaLalaL laLala};             
        \node [square, below = 10mm of CRS12] (LSQ12) {Lal aLalaLal aLalaL alaLal aLala LalaLala.};              
        \node [square, below = 10mm of CRS22] (LSQ22) {LLa aLalaLal aLa laLal aLal aLalaala};           
        \node [square] (CRSBoth) at ($(LSQ12)!50!(LSQ22)$) {Lal LalaLal aLalaL ala LalaLala LalaLala};
        \node[square,below of=CRSBoth] {Lala LalaL alaLalaLala LalaLalaLala Lala};
        \end{tikzpicture}
    }
  \caption{Lala.}\label{Lala}
    \end{subfigure}
  \caption{LalaLala}
  \label{LalaLalaLala}
  \end{figure*}
  \end{document}
3

To start with \linewidth is the width of a text line. In normal one column text it is the same as the text width (\textwidth) but in two columns it is the width of a column. When you say

\begin{subfigure}[t]{.5\linewidth}
  \resizebox{\linewidth}{!}{

you say first to make a subfigure of with 0.5\linewdith, that is half the line width. Inside this box the text width spans half the global text width. That is, the local \linewidth is the width of the subfigure. So the second line scales your tikzpicture to fit the box.

The black boxes are not just black boxes, they are your nodes. I am not sure what you want to do with ($(LSQ12)!50!(LSQ22)$), but the effect is that the node (and (CRSBoth)) far away to the right. Try to write just the picture without \resizebox and enclose the picture in an \fbox and you see it continues outside the paper. I changed the !50! to a + and then it looks much better (mayby not what you want but much better:).

Finally I removed the ~ between the subfigures and added a % after the first. The reason is that both your subfigures are 0.5\linewidth and then there is not room for more space in between them.

\documentclass[twocolumn, 10pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[hypcap = true]{subcaption}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\usetikzlibrary{shapes.geometric, positioning, automata, arrows, calc}
\begin{figure*}[!hbtp]
  \tikzstyle{square}=[rectangle,thick,minimum size=0.5cm,draw=black!100,fill=blue!20]
  \begin{subfigure}[t]{.5\linewidth}
    \centering
    \resizebox{\linewidth}{!}{
      \begin{tikzpicture}[auto, outer sep=3pt, node distance=2cm,>=latex']
        \node [square, text width = .8\textwidth] (Draw) {LalaLal aLalaLal aLalaL alaLalaLalaLal aLalaLala LalaLala};
        \node [square, below = 15mm of Draw, text width = .7\textwidth] (Matrix) {LalaLala LalaL alaLalaLalaLa laLa laLalaL alaLa laLal aLalaLala LalaL alaLal aLala};
        \node [square, below = 12mm of Matrix] (TrialMatrix) {Experiment matrix of a subset of the trial points.};
        \node [square, below = 15mm of TrialMatrix] (TrialPoint) {La laL al aLala Lala LalaL alaLa laLalaLalaLal aLalaLala};
        \node [square, below = 10mm of TrialPoint] (Pnew) {LalaLalaL ala LalaL alaLal aLala LalaLa laL alaL ala Lala };
        \node [below = 20mm of Pnew] (LogicGate) {};
        \node [square, right = 30mm of LogicGate] (Penalty) {LalaLalaLa laLal aLalaLa laLal aLa laLala};
        \node [square, below = 10mm of Penalty,fill=red!20] (PenaltyEnd) {LalaLalaLala};
        \node [square, left = 15mm of LogicGate,text width = .6\textwidth] (Replace) {RLa laLalaLal aLala LalaLa laLal aLal aLala};
        \node [square, below = 10mm of LogicGate,text width = .6\textwidth] (Criteria) {Lala LalaLala LalaLa la};
        \draw [thick,->] (Draw.south) to node [above left] {Lal aLa laLa la Lal aLa la Lala } node [above right] {fLala La laLa laLala} node [left] {Lal aL ala LalaLal a} node [right] { Lala Lala Lala Lala} node [below left] {} node [below right] {} (Matrix.north);
        \draw [thick,->] (Matrix.south) to node [left] {La laL ala LalaL al aLa la} node [right] {LalaL alaLa la Lala} node [below left] {Lala Lal aL alaLa la} node [below right] {Lal aLala Lala} (TrialMatrix.north);
        \draw [thick,->] (TrialMatrix.south) to node [above left] {Lala LalaLa laLal aLala} node[above right] {LalaL alaLal aLalaLal aLalaL alaL ala La laLal a} node [left] {LalaL alaLal aLalaLal aLalaLal aLalaL alaLalaLa laLalaLa laLala} node [right] {La laL alaLalaL alaLalaL alaLalaLal aLalaL alaLala } node [below left] {La laLalaLa laLalaLa laLalaL alaLal aLala} node [below right] {random trial point. $P_{new}=2{\times}\overline{P}-P_{r}$}(TrialPoint.north);
        \draw [thick, ->] (TrialPoint.south) -- node [left] {La la LalaLa l aLal aLa laLal aLala} node [right] {La laLal aLal aLala Lala Lala Lala} (Pnew.north);
        \draw [thick,->] (Pnew.south) -- node [above left] {LalaL alaLal aLala LalaL alaLala} node [above right] {La laLala LalaLala} node [left] {LalaL a laL alaL ala} node [right] { Lala Lal aLala } node [below left] {Lal aLa laLala} node [below right] {La laL alaLala.} (LogicGate);
        \draw [thick,->] (LogicGate) -- node [below] {LalaLala} (Penalty);
        \draw [thick,->] (LogicGate) -- node [below] {} (Criteria);
        \draw [thick,->] (LogicGate) -- node [below] {Lala Lala Lala} (Replace);
        \draw [thick,->] (Penalty) -- node[left] {Lala} node [right] {LalaLalaLala} (PenaltyEnd);
        \draw [thick,->] (Penalty.east) -- ($(Penalty.east) - (-.3,0)$) |- node [below left] {La Lalalala} (Matrix.east);
        \draw [thick,->] (Criteria.west) -- node [above] {Lala} ($(Criteria.west) - (4.6,0)$) |- (Matrix.west);
        \draw [thick,->] (Criteria.east) -- node [above] {Lqlq} (PenaltyEnd.west);
      \end{tikzpicture}
    }
    \caption{Lala
    }\label{LalaLala}
  \end{subfigure}%
  \begin{subfigure}[t]{.5\linewidth}
    \centering
    \resizebox{\linewidth}{!}{
      \begin{tikzpicture}[auto, outer sep=3pt, node distance=2cm,>=latex']
        \node [square](CRS12) {Lala LalaLalaLala Lala};
        \node [square, right = 30mm of CRS12] (CRS22) {LalaL alaLalaLalaLa laLalaLalaL laLala};
        \node [square, below = 10mm of CRS12] (LSQ12) {Lal aLalaLal aLalaL alaLal aLala LalaLala.};
        \node [square, below = 10mm of CRS22] (LSQ22) {LLa aLalaLal aLa laLal aLal aLalaala};
        \node [square] (CRSBoth) at ($(LSQ12)+(LSQ22)$) {Lal LalaLal aLalaL ala LalaLala LalaLala};
        \node[square,below of=CRSBoth] {Lala LalaL alaLalaLala LalaLalaLala Lala};
      \end{tikzpicture}
    }
    \caption{Lala.}\label{Lala}
  \end{subfigure}
  \caption{LalaLala
  }\label{LalaLalaLala}
\end{figure*}

\end{document}

enter image description here

  • Ah, thank you for clarifying some of my errors. ($(LSQ12)!50!(LSQ22)$) was supposed to place the node in between the two. I actually wanted it in-between and below the two bottom nodes, but thought I would just yshift it once I had in between. And again thank you for clarifying some important points when scaling images. – Baraliuh Dec 21 '16 at 7:42
2

Scaling images is on one hand convenient, but on the other hand at significantly shrinking of image text in it fast become unreadable. This happens in your case. So I suggest to consider to redesign your flowcharts. In this, is advisable to ask yourself the following question:

  • is really needed so long labels of edges?
  • is really needed so long text in nodes?
  • can nodes have more than one lines?
  • which is the smallest font size, that text can be read without magnifying glass?

See, if the following solution, where i for last tow questions choose more lines in nodes and \footnotesize for the smallest acceptable font size. Beside this, I simplify code and made it concise where was possible:

\documentclass[twocolumn, 10pt]{extarticle}
  \usepackage[utf8]{inputenc}
  \usepackage[english]{babel}
  \usepackage{csquotes}
  \usepackage[T1]{fontenc}
  \usepackage{amsmath}
  \usepackage[hypcap = true]{subcaption}
  \usepackage{tikz}
  \usetikzlibrary{arrows, positioning, }

\usepackage{showframe}% for show page layout, in real document had to be removed
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
    \begin{figure*}
\tikzset{
       font = \footnotesize,
line/.style = {thick, -latex', shorten >=1mm, shorten <=1mm},
 box/.style = {thick, draw, fill=blue!20,
               minimum height=7mm, text width = #1, align=center},
 ELL/.style = {left, align=right},% edge label left
 ELR/.style = {right, align=left},% edge label right
 box/.default = 0.4\linewidth
        }
\begin{subfigure}[t]{.60\textwidth}
    \centering
%\resizebox{\linewidth}{!}{
    \begin{tikzpicture}[node distance = 11mm and 18mm]
    \begin{scope}[every node/.style = {box}]
\node (Draw) {LalaLal aLalaLal aLalaL alaLalaLalaLal aLalaLala LalaLala};
\node [below=of Draw] (Matrix) {LalaLala LalaL alaLalaLalaLa laLa laLalaL alaLa laLal aLalaLala LalaL alaLal aLala};
\node [below=of Matrix] (TrialMatrix) {Experiment matrix of a subset of the trial points.};
\node [below = 21mm of TrialMatrix] (TrialPoint) {La laL al aLala Lala LalaL alaLa laLalaLalaLal aLalaLala};
\node [below= of TrialPoint] (Pnew) {LalaLalaL ala LalaL alaLal aLala LalaLa laL alaL ala Lala};
\coordinate[below = 21mm of Pnew] (LogicGate) {};
    \begin{scope}[box/.default = 0.25\linewidth]
\node [right = of LogicGate] (Penalty) {LalaLalaLa laLal aLalaLa laLal aLa laLala};
\node [left =of LogicGate] (Replace) {RLa laLalaLal aLala LalaLa laLal aLal aLala};
\node [below = of LogicGate] (Criteria) {Lala LalaLala LalaLa la};
\node [at={(Criteria-| Penalty)},fill=red!20] (PenaltyEnd) {LalaLalaLala};
    \end{scope}
    \end{scope}
\draw [line]    (Draw) to  
    node [ELL]  {Lal aLa laLa la Lal aLa la Lala\\
                 Lal aL ala LalaLal a} 
    node [ELR]  {fLala La laLa laLala\\
                 Lala Lala Lala Lala} 
                (Matrix);
\draw [line]    (Matrix) to 
    node [ELL]  {La laL ala LalaL al aLa la\\
                 Lala Lal aL alaLa la} 
    node [ELR]  {LalaL alaLa la Lala\\
                  Lal aLala Lala} 
                (TrialMatrix.north);
\draw [line]    (TrialMatrix) to 
    node [ELL]  {Lala LalaLa laLal aLala LalaL \\
                 alaLal aLalaLal aLalaLal aLal \\
                 LalaLa laLalaLa laLala La laL \\
                 laLalaLa laLalaL alaLal aLala} 
    node [ELR]  {LalaL alaLal LalaLal aaL alaL\\ 
                 Lalala La laLal a La laL alaLalaL\\
                 alaLalaLal aLalaL alaLala\\
                 random trial point\\ $P_{new}=2{\times}\overline{P}-P_{r}$}
                 (TrialPoint);
\draw [line]    (TrialPoint) to 
    node [ELL]  {La la LalaLa l aLal\\
                 aLa laLal aLala} 
    node [ELR]  {La laLal aLal aLala\\
                 Lala Lala Lala} 
                (Pnew);
\draw [line]    (Pnew) to
    node [ELL] {LalaL Lal aLala LalaL alaLala\\
                LalaL a laL alaL ala\\
                Lal aLa laLala}
    node [ELR] {La laLala LalaLala\\
                Lala Lal aLala\\
                La laL alaLala.} 
                (LogicGate |- Penalty.north) -- (LogicGate);
\draw [line]    (LogicGate) to node [below] {LalaLala} (Penalty);
\draw [line]    (LogicGate) to 
    node [below,align=center] {Lala Lala\\ Lala} (Replace);
    \draw [line] (LogicGate) to (Criteria);
\draw [line]    (Penalty) to 
    node [ELL]  {Lala} 
    node [ELR]  {LalaLalaLala} 
                (PenaltyEnd);
\draw [line]    (Penalty.east) -- ++(0.4,0) |- 
    node [pos=0.75,below] {La Lalalala} 
                    (Matrix);
\draw [line]    (Criteria) -| 
    node [pos=0.25,above] {Lala} 
            ([xshift=-3mm] Replace.west) |- (Matrix.west);
\draw [line] (Criteria) to node [above] {Lqlq} (PenaltyEnd);
        \end{tikzpicture}
%        }
\caption{Lala}
    \label{LalaLala}
    \end{subfigure}
\hfill
    \begin{subfigure}[t]{.39\textwidth}
    \centering
%\resizebox{\linewidth}{!}{
    \begin{tikzpicture}[
node distance = 12mm and 4mm,
 box/.default = 0.42\linewidth,
every node/.style = {box}
                        ]
\node (CRS12) {Lala LalaLalaLala Lala};
\node [below = of CRS12] (LSQ12) {Lal aLalaLal aLalaL alaLal aLala LalaLala.};
\node [right = of CRS12] (CRS22) {LaL alaLalaLalaLa laLalaLalaL laLala};
\node [below = of CRS22] (LSQ22) {LLa aLalaLal aLa laLal aLal aLalaala};
\node [below = of LSQ22] (CRSBoth) {Lal LalaLal aLalaL ala LalaLala LalaLala};
\node [box,below = of CRSBoth]          {Lala LalaL alaLalaLala LalaLalaLala Lala};
        \end{tikzpicture}
%    }
  \caption{Lala.}\label{Lala}
    \end{subfigure}
  \caption{LalaLala}
  \label{LalaLalaLala}
  \end{figure*}
  \end{document}

enter image description here

Note: In proposed MWE are used very basic possibilities of TikZ package. They are described in TikZ & PGF Manual for Version 3.0.1a in parts "I Tutorials and Guidelines" and "III TikZ is kein Zeichenprogramm". It is worth to read them.

Regarding \tikzset{...}: in it are collected styles of all used images' elements, from font size to features of used nodes (it is used instead of deprecated tikzstyle). Three kind of nodes are used:

  • box which has defined thick border (draw), blue fill, minimum height and text width as parameter and text is centered by align=center. Last two option deal with formatting text in node. Its maximal width is limited with text width. If it is longer, it is automatically broken in new line. I this is aligned according to align=center. Options text with and align=... make node's text behavior similar to behavior of text in \parbox{<width>}{...}.
  • ELL (Edge Line on the Left side) in comparison to your code new picture element) which is dedicated to be on the left side of edges and aligned to its right side. The align= ... enables to write multi line text with manual breaking of lines like \draw (<coordinate 1>) to node[ELL] {text in the first line\\ text in the second line`` ...} (<coordinate 2>);. Manual breaking is selected since the available space for it is depend from positions of edges.
  • ELR (Edge Line on the Right side) are similar asELL` but for opposite edges' side.

Beside this styles are defined styles for:

  • line determine edges style. Here is added shortening of edges (instead to your selection outer sep=3pt, which can cause problems in node positioning)
  • box/.default is used to determine default value of text width in box nodes. This way is selected because in the first flowchart are two text width sizes.

At each tikzpicture are determined `node distance = and , by which are for whole picture are determined distances (with one exception) between all nodes in flowcharts.

Regarding used coordinates:

  • (<coordinate 1> |- <coordinate 2>) determine coordinate on intersections of of vertical line through coordinate 1 and horizontal line through coordinate 2.
  • similarly (<coordinate 1> -| <coordinate 2>) determine coordinate on intersection of horizontal line through coordinate 1 and vertically through coordinate 2
  • for drawing edges it is sufficient to use only coordinate name (without explicitly defined anchor on node shape). Anchor of shape had to be explicitly defined in case of use shift option for determining new coordinates (for example ([xshift=-3mm] Replace.west) determine coordinate on position 3mm left from west side of node shape), otherwise it consider anchor center

In the first picture the nodes are grouped with scope by which is defined common node features: they have box style with default text width, which is the inner scope changed to smaller size. By this nodes code for become more concise and clear.

With all this measures the \adjustbox become unnecessary. To my conviction is better to prevent than cure with all side effect (in your case unreadable image contents and consequently with questionable worth). Also I hope that this answer can serve as step in your TikZ learning process :).

  • Thank you for some nice tips and tricks. I have already tried to make the flow chart a bit less wordy. "\tikzset{ font = \footnotesize," This one I didn't think of. Thank you its a very nice one to use. Your code is very nice, but almost a bit too advanced for me to fully be able to appreciate it. How is it that you can use line breaks in the arrow text? E.g. \draw [line] (Pnew) to node [ELL] {[...]\\ [...]\\ [...]} node [ELR] {[...]\\ [...]\\ [...].} (LogicGate |- Penalty.north) -- (LogicGate); – Baraliuh Dec 21 '16 at 7:52
  • 1
    @Baraliuh, I add some explanation to my answer. And I had to say: my code is not advanced, rather very basic and simple :) and it differ from your MWE in small details, which make both pictures usable. – Zarko Dec 21 '16 at 12:08
  • WOW! This is great! This will definitely be a great homework for me to go over a few times and have to look back at when I do my TikZ coding. Thank you, sir, and all the kudos in the world to you! – Baraliuh Dec 22 '16 at 13:21

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.