0

after smashing my .tex file I am wondering why my Tikzpicture isnt right. It looked like this:

before

I started to export the Tikzpictures into single pdf-files. The same Code (ignoring the node positions and caption title):

\documentclass[tikz]{article}
\usepackage{tikz}
\pagestyle{empty}
\usepackage{subcaption}
\definecolor{tokloGrey}{rgb}{0.68,0.68,0.68}
\definecolor{tkblue}{rgb}{0,0.212,0.369}
\definecolor{tkred}{rgb}{1,0.064,0.064}

\begin{document}
\begin{figure}[htbp]  
\centering 
  \begin{subfigure}{0.3\linewidth}
    \centering
    \scalebox{0.9}{\begin{tikzpicture}[domain=0:3]
        \draw[tkblue,thick] plot (\x,0.25*\x*\x+1);
        \draw[very thin,gray] (0,-0.4) grid (3.1,3.4);
        \draw[->] (0,0) -- (3.2,0) node[right] {$x$};
        \draw[->] (0,-0.5) -- (0,3.5) node[above] {$f(x)$};
        \draw[tkblue,thick] (2.45,3.5) node[] {$f(\mathrm{x}) = \mathrm{ax}^2+\mathrm{b}$};
        \end{tikzpicture}}%
        \caption{nicht-lineare Funktion}
        \label{fig:M1}  
  \end{subfigure}
\begin{subfigure}{0.3\linewidth}
    \centering
    \scalebox{0.9}{\begin{tikzpicture}[domain=0:3]
        \draw[tkblue,thick] plot (\x,2);
        \draw[very thin,gray] (0,-0.4) grid (3.1,3.4);
        \draw[->] (0,0) -- (3.2,0) node[right] {$x$};
        \draw[->] (0,-0.5) -- (0,3.5) node[above] {$f(x)$};
        \draw[tkblue,thick] (2.45,3.5) node[] {$f_{\overline{\mathrm{DC}}}(\mathrm{x}) = \mathrm{AP}$};
    \end{tikzpicture}}
    \caption{Gleichanteil (Arbeitspunkt)}
    \label{fig:M2}  
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
    \centering
    \scalebox{0.9}{\begin{tikzpicture}[domain=0:3]
        \draw[tkblue,thick] plot (\x,0.25*\x*\x+1) node[above] {$f(x)$};
        \draw[very thin,gray] (0,-0.4) grid (3.1,3.4);
        \draw[tkred,<->,thick] (1.75,1.75) -- (2.25,2.25);
        \fill[black] (2,2) circle (1.5pt);
        \draw[black] (1.8,2.15) node{{\scriptsize $\mathrm{AP}$}};
        \draw[tokloGrey,<->,thin] (1.75,1.65) -- (2.25,1.65);
        \draw[tokloGrey] (2,1.5) node{{\scriptsize $\Delta\mathrm{x}$}};
        \draw[tokloGrey] (2.65,2) node{{\scriptsize $\Delta\mathrm{y}$}};
        \draw[tokloGrey,<->,thin] (2.35,1.75) -- (2.35,2.25);
        \draw[->] (0,0) -- (3.2,0) node[right] {$x$};
        \draw[->] (0,-0.5) -- (0,3.5) node[above] {$y$};
        \end{tikzpicture}}
        \caption{Transienter Anteil (Linear)}
\label{fig:M2}  
\end{subfigure}
\caption{Linearisierung durch Perturbation in einem Arbeitspunkt}
\label{fig:lin_perturb}
\end{figure}  
\end{document}

Results now into:

after

As you can see, the Figures are compressed to each other.. Also if I replace the "article" with the "Standalone" documentclass, the compilation doesnt work:

exmp.tex:20: Improper \prevdepth.
\newpage ...everypar {}\fi \par \ifdim \prevdepth 
                                                  >\z@ \vskip -\ifdim \prevd...
l.20         \end{tikzpicture}}
                               %
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.20         \end{tikzpicture}}
                               %
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: Missing } inserted.
<inserted text> 
                }
l.20         \end{tikzpicture}}
                               %
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: Missing } inserted.
<inserted text> 
                }
l.20         \end{tikzpicture}}
                               %

c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: LaTeX Error: \begin{subfigure} on input line 12 ended by \end{tikzpicture}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.20         \end{tikzpicture}}
                               %
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: Extra }, or forgotten \endgroup.
\Gscale@box ...cale@y {#2}\setbox \z@ \hbox {{#3}}
                                                  \setbox \tw@ \hbox {\Gscal...
l.20         \end{tikzpicture}}
                               %
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: Undefined control sequence.
<argument> \Gscale@x 

l.20         \end{tikzpicture}}
                               %
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:20: Undefined control sequence.
<argument> \Gscale@y 

l.20         \end{tikzpicture}}
                               %
[1]
Overfull \hbox (38.2223pt too wide) in paragraph at lines 21--21
[]\OT1/cmr/m/n/10 Figure 1:

Overfull \hbox (25.00003pt too wide) in paragraph at lines 21--21
|\OT1/cmr/m/n/10 nicht-

Overfull \hbox (28.91672pt too wide) in paragraph at lines 21--21
\OT1/cmr/m/n/10 lineare

Overfull \hbox (25.41673pt too wide) in paragraph at lines 21--21
\OT1/cmr/m/n/10 Funk-

Overfull \hbox (17.22227pt too wide) in paragraph at lines 21--21
\OT1/cmr/m/n/10 tion| 
c:/Users/Tobias/OneDrive/Desktop/exmp.tex:23: Extra }, or forgotten \endgroup.
\endminipage ...pagefalse \color@endgroup \egroup 
                                                  \expandafter \@iiiparbox \...
l.23   \end{subfigure}

c:/Users/Tobias/OneDrive/Desktop/exmp.tex:23: Undefined control sequence.
\endminipage ...\expandafter \@iiiparbox \@mpargs 
                                                  {\unvbox \@tempboxa }
l.23   \end{subfigure}

)
Runaway argument?
\@checkend {subfigure}\expandafter \endgroup \if@endpe \@doendpe \fi \ETC.
! File ended while scanning use of \@iiiparbox.
<inserted text> 
                \par 
<*> c:/Users/Tobias/OneDrive/Desktop/exmp.tex

! Emergency stop.
<*> c:/Users/Tobias/OneDrive/Desktop/exmp.tex

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on exmp.log.
Collected error summary (may duplicate other messages):
  pdflatex: Command for 'pdflatex' gave return code 1
      Refer to 'exmp.log' for details
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs, or warnings treated as errors.
=== TeX engine is 'pdfTeX'
Latexmk: Errors, so I did not complete making targets

What happened?

7
  • Did you consider \usepgfplotslibrary{groupplots}? Maybe this works better.
    – cis
    Apr 7 '20 at 19:06
  • Do you mean to inserting the line?
    – adaptive
    Apr 7 '20 at 19:08
  • You cannot have floats like figures in standalone class (easily). @cis This is not a pgfplots document.
    – user194703
    Apr 7 '20 at 19:09
  • @adaptive I thought for the alignment. @ Schrödinger's cat I used the groupplots-libraray for plain-TikZ stuff as well, with success. ;) But I did not try to convert here.
    – cis
    Apr 7 '20 at 19:11
  • 1
    Did you already consider using \begin{subfigure}[t]{0.3\linewidth} in combination with \hfill between adjacent sibfigure environments?
    – leandriis
    Apr 7 '20 at 19:21
3
  • don't use \scalebox
  • between subfigures insert \hfill commands they will push images apart
  • add to subfigure option [t]:
\documentclass[tikz]{article}
\usepackage{tikz}
\pagestyle{empty}
\usepackage{subcaption}
\definecolor{tokloGrey}{rgb}{0.68,0.68,0.68}
\definecolor{tkblue}{rgb}{0,0.212,0.369}
\definecolor{tkred}{rgb}{1,0.064,0.064}

\begin{document}
    \begin{figure}[htbp]
\begin{subfigure}[t]{0.3\linewidth}
    \centering
    \begin{tikzpicture}[domain=0:3]
        \draw[tkblue,thick] plot (\x,0.25*\x*\x+1);
        \draw[very thin,gray] (0,-0.4) grid (3.1,3.4);
        \draw[->] (0,0) -- (3.2,0) node[right] {$x$};
        \draw[->] (0,-0.5) -- (0,3.5) node[above] {$f(x)$};
        \draw[tkblue,thick] (2.45,3.5) node[] {$f(\mathrm{x}) = \mathrm{ax}^2+\mathrm{b}$};
        \end{tikzpicture}%
        \caption{nicht-lineare Funktion}
        \label{fig:M1}
  \end{subfigure}\hfill
\begin{subfigure}[t]{0.3\linewidth}
    \centering
        \begin{tikzpicture}[domain=0:3]
        \draw[tkblue,thick] plot (\x,2);
        \draw[very thin,gray] (0,-0.4) grid (3.1,3.4);
        \draw[->] (0,0) -- (3.2,0) node[right] {$x$};
        \draw[->] (0,-0.5) -- (0,3.5) node[above] {$f(x)$};
        \draw[tkblue,thick] (2.45,3.5) node[] {$f_{\overline{\mathrm{DC}}}(\mathrm{x}) = \mathrm{AP}$};
    \end{tikzpicture}
    \caption{Gleichanteil (Arbeitspunkt)}
    \label{fig:M2}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.3\linewidth}
    \centering
    \begin{tikzpicture}[domain=0:3]
        \draw[tkblue,thick] plot (\x,0.25*\x*\x+1) node[above] {$f(x)$};
        \draw[very thin,gray] (0,-0.4) grid (3.1,3.4);
        \draw[tkred,<->,thick] (1.75,1.75) -- (2.25,2.25);
        \fill[black] (2,2) circle (1.5pt);
        \draw[black] (1.8,2.15) node{{\scriptsize $\mathrm{AP}$}};
        \draw[tokloGrey,<->,thin] (1.75,1.65) -- (2.25,1.65);
        \draw[tokloGrey] (2,1.5) node{{\scriptsize $\Delta\mathrm{x}$}};
        \draw[tokloGrey] (2.65,2) node{{\scriptsize $\Delta\mathrm{y}$}};
        \draw[tokloGrey,<->,thin] (2.35,1.75) -- (2.35,2.25);
        \draw[->] (0,0) -- (3.2,0) node[right] {$x$};
        \draw[->] (0,-0.5) -- (0,3.5) node[above] {$y$};
        \end{tikzpicture}
        \caption{Transienter Anteil (Linear)}
\label{fig:M2}
\end{subfigure}
\caption{Linearisierung durch Perturbation in einem Arbeitspunkt}
\label{fig:lin_perturb}
    \end{figure}
\end{document}

enter image description here

5
  • Thanks! that looks good. But how do I get that into a scalable *.pdf without being pictured onto A4?
    – adaptive
    Apr 7 '20 at 19:49
  • @adaptive, sorry, I don't understand what you mean with "scalable". This figure is scalable as other part of your document. So far i see no reason to scale anything.
    – Zarko
    Apr 7 '20 at 19:53
  • Ok sorry. If i compile the Code I get an A4 Page with that Image because of the documentclass "article".. I would like to use "standalone" to get only the Picture, so that I can embed that pdf.
    – adaptive
    Apr 7 '20 at 19:54
  • In standalone you can not use figure environment. If I understand you correctly, than you need to draw each image separately and include them as code file in subfigure (via input) or as pdf file (via \includegraphics). Please, edit your question and clarify, what actually is your problem.
    – Zarko
    Apr 7 '20 at 19:58
  • The problem is solved! Thanks!
    – adaptive
    Apr 7 '20 at 20:10

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.