3

I have a standalone standalone_tikzpicture.tex file,

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes,arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[
sum/.style= {draw, circle},
input/.style = {coordinate},
output/.style= {coordinate},
>=Stealth,
]
\node [input, name=input1] (input1) {};
\node [sum, right of=input1, name=sum1] (sum1) {$ + $};
\node [output, right of=sum1, name=output1] (output1) {};
\draw [->] node [left] {$\textbf{A}$} (input1) -- (sum1);
\draw [->] (sum1) -- (output1) node [right] {B};
\end{tikzpicture}
\end{document}

which I want to display in another file main.tex with different scale. My main.tex file is:

\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{arrows.meta,shapes,arrows,positioning,calc}
\begin{document}
\foreach \i in {0.5,1,...,4}{
\begin{figure}\label{fig:\i}
    \tikzset{every picture/.style={scale=\i,every picture/.style={}}}
    \centering
    \includestandalone{standalone_tikzpicture}
    \caption{Figure size \i.}
\end{figure}
}
\end{document}

Problem is, the standalone picture isn't scaled in the output of main.tex. Figure with same size is obtained. The only way I could scale is by replacing line

\includestandalone{standalone_tikzpicture}

with

\includestandalone[scale = \i]{standalone_tikzpicture}

but this scales texts as well which is definitely not desired. I have read Best way to include a standalone tikz file and scale it without scaling the nodes, solutions in it is not working for me. Is there a way to keep font size same and scale only picture?

Edit1 (Missed to add requirement):

\foreach is used here only to simulate multiple instances of same picture. Requirement is to use the same picture in different places. Hence standalone_file is required.

  • Admittedly I don't get either \includestandalone or externalize, but [class=minimal]? There is very little defined in the minimal class, and certainly nothing which is used here. – John Kormylo Oct 19 '17 at 4:27
  • @JohnKormylo I have updated the code as per your suggestion and removed [class=minimal] from \documentclass[class=minimal]{standalone} in file standalone_tikzpicture.tex. Nevertheless, it has no visible effect on scaling than before. – ItzMe Oct 19 '17 at 8:55
  • While tikzpicture itself scales only the drawing and not the text, you would have to pass the option to standalone somehow. Perhaps create a file in the main document and use \input in the standalone. Or you could just not use \includestandalone at all. – John Kormylo Oct 19 '17 at 15:55
  • Can you please give examples. I could not get it work. – ItzMe Oct 19 '17 at 18:59
  • 1
    The \includestandalone[scale = \i] scales the content as a whole box. It is not related to TikZs scale which scales coordinates. standalone can't change TikZ code afterwards. One solution is to define your scale setting as macro in the main document which is then used in the subfiles after beeing set to the wanted value before every inclusion. – Martin Scharrer Nov 24 '17 at 7:54
1

The following scaled inner sep to make the circle bigger, and specified the separation distance directly. I'm not sure what separation distance left of uses, but it isn't either inner sep or outer sep.

I made no attempt to use standalone. That is a separate problem.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\foreach \i in {0.5,1,...,4}{%
\begin{figure}
    \centering
    \begin{tikzpicture}[
      every node/.style={inner sep={\i*.333em}},
      sum/.style= {draw, circle},
      >=Stealth,
      ]
      \node [sum] (sum1) {$ + $};
      \node [right={\i*1em}] (output1) at (sum1.east) {B};
      \node [left={\i*1em}] (input1) at (sum1.west) {$\textbf{A}$};
      \draw [->] (input1) -- (sum1);
      \draw [->] (sum1) -- (output1);
    \end{tikzpicture}
    \caption{Inner sep scale = \i, separation distance = \i em.}
\end{figure}
}
\end{document}
  • Even though your code works for my initial question, I had a different intension. I added \foreach to simulate multiple instances of same picture. But the picture is reused in different places. So I kept standalone file to be able to reuse the code and to adjust pictures in all instances by changing code only in standalone file. I will post my solution. I have 3 methods now. First 2 methods inspired by your answer. I did not realize the dependence of node size on the text inside it, thanks for pointing it out. Third solution in my post is the ideal one I was looking for. – ItzMe Oct 21 '17 at 14:47
1

I have found three ways to solve the problem. Requirement of having a separate standalone file is maintained in these solutions.

How to use files for each solution:

  • Main file: Read all comments in main.tex to turn on and off appropriate lines for each solution. This file is required file for all solutions.

  • For solution 1 and solution 2: Read all comments in standalone_tikzpicture12.tex to turn on and off appropriate lines for solution 1 and solution 2.

  • For solution 3: Please use standalone_tikzpicture3.tex.

Each solution in detail:

  1. Solution 1: \tikzset{every picture/.style={scale=\i, every picture/.style={}}} can be used in main.tex to scale only shapes as per argument \i and by not sending the variable explicitly to the standalone file standalone_tikzpicture12.tex.

  2. Solution 2: From main.tex send argument \i explicitly to standalone file standalone_tikzpicture12.tex and scale each shape with \draw[scale=\i] option. In standalone_tikzpicture12.tex, all shapes are drawn with absolute scale. Nodes are created only to add text and without any shapes around it. This is common to solution 1 and 2. This becomes challenging for more complex figure. These two methods evolved after I learned from @JohnKormylo that size of nodes fit to contents inside.

  3. In Solution 3, a standalone file standalone_tikzpicture3.tex is created not much different that the one posted in the Question, but with additional changes. Argument \i is sent explicitly to the standalone file, and also the whole tikzpicture is scaled in the main.tex file using \includestandalone[scale=\i]{standalone_picture3}. In standalone_tikzpicture3.tex file all nodes are created with shapes with parameters such as node distance, minimum size, circle, etc as per required sizes without any text inside. For each text, nodes are created with parameter [scale=1/\i] and this makes the difference. This nullifies scaling effect made by [scale=\i] in the main.tex. Scale everything by \i and again scale only texts by 1/\i to nullify the scale. Also explicitly using any other variable to adjust scale of only texts is possible here.

Code (by default solution 3 is enabled):

main.tex (Required for all solutions):

    \documentclass{article}
    \usepackage{tikz}
    \usepackage{standalone}
    \usepackage{tikzscale}
    \usetikzlibrary{arrows.meta,shapes,arrows,positioning,calc}
    \begin{document}
    \foreach \i in {1,2,...,4}{
    \begin{figure}\label{fig:\i}
        \centering
%        \def\i{<MyScaleValue>} % assign a value to \i in General cases when not using \foreach to set \i

%        Enable below 1 line for method 1, Disable for method 2 and 3        
%        \tikzset{every picture/.style={scale=\i, every picture/.style={}}} % Method 1
%        Enable below 1 line for method 1 and 2, Disable for method 3
%        \includestandalone{standalone_picture12} % This is for method 1 and 2

%        Enable below line for method 3, Disable for method 1 and 2
        \includestandalone[scale=\i]{standalone_picture3} % This is for method 3

        \caption{Figure size \i.}
    \end{figure}
    }
    \end{document}

standalone_picture12.tex (Standalone file for Solution 1 and 2):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[
    >=Stealth,
    ]
%    Enable below 1 line for method 1, Disable for method 2
    \def\i{1} % Method 1
    \def\ii{0.25*\i}
    \def\ij{3}
    \draw [domain=0:360, scale = \ii] plot ({cos(\x)}, {sin(\x)});
    \draw [->] (-\ii*\ij,0) -- (-\ii,0);
    \draw [->] (\ii,0) -- (\ii*\ij,0);
    \draw [line width = \ii] (-\ii*.75,0) -- (\ii*.75,0);
    \draw [line width = \ii] (0,-\ii*.75) -- (0,\ii*.75);
    \node [anchor=east] at (-\ii*\ij,0) {$ \textbf{A} $};
    \node [anchor=west] at (\ii*\ij,0) {$ \textbf{B} $};
    \end{tikzpicture}
\end{document}

standalone_picture3.tex (Standalone file for Solution 3):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[
    node distance = 10mm and 10mm,
    sum/.style= {draw, circle, minimum size=6mm, inner sep=0pt, outer sep=0pt,},
    input/.style = {coordinate},
    output/.style= {coordinate},
    >=Stealth,
    ]
%    \def\i{1} % to test standalone
    \def\j{1} % to test standalone
    \node [input,] (input1) {};
    \node [sum, right=of input1,scale=\j] (sum1) {$ + $};
    \node [output, right=of sum1,scale=\j] (output1) {};
    \draw [->,scale=\j] (input1) -- (sum1);
    \node [anchor=east,scale=1/\i] at (input1) (A) {$\textbf{A}$};
    \draw [->,scale=\j] (sum1) -- (output1);
    \node [anchor = west,scale=1/\i] at (output1)  (B) {$ \textbf{B} $};
    \end{tikzpicture}
\end{document}

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.