3

I've advanced a bit and drawn a couple of diagrams. Via /begin{figure} I've managed to align the first two. However, the third one won't align the way I want. Obviously this is due to the different y-label i_L. How can I make sure all diagrams will get aligned the same way so that each DT, T/2... sits flush?

% Basierend auf einer Vorlage von: Author: Urs Zellweger ([email protected]),s. http://texample.net/tikz/examples/phasor-diagram/ % Mit Hilfe von tex.stackexchange.com Coordinate system all set up - how to fill it now?

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}


%\newcommand{\Gitter}[4]{ % Für die Gitterliniene, Änderungen hier betreffen ALLE Gitter %im Latex Dokument
%    \draw[very thin,color=gray] (#1,#3) grid (#2,#4);
%}

\newcommand{\Koordinatenkreuz}[6]{ % Für das Koordinatenkreuz, Änderungen hier betreffen ALLE Gitter im Latex Dokument
    \draw[->, >=latex, color=green!50!black] (#1,0) -- (#2,0) node[right] {#5};
    \draw[->, >=latex, color=green!50!black] (0,#3) -- (0,#4) node[left] {#6};
}

\newenvironment{Diagramm}[5]{ 
\begin{tikzpicture}
    \def\T{#1}
    \def\Thalf{#2}
    \def\DT{#3}
    \def\Label{#4}
    \def\Yrange{#5}

    %\Gitter{-.1}{10.1}{#5-0.1}{3.1}
    \Koordinatenkreuz{-.2}{10.3}{#5-0.2}{2.8}{$t$}{#4};
    \draw (#1,0) node[below]{$T$};
    \draw (#2,0) node[below]{$\frac{T}{2}$};
    \draw (#3,0) node[below]{$DT$};
}
{\end{tikzpicture}}


\begin{document}


% {T}{T/2}{DT}{y-Label}{negative y-range}
\begin{figure}
\centering
\begin{Diagramm}{8}{4}{2}{$U_{GS_{1,4}}$}{0}
\draw [thick,red] (0,2) --++ (2,0) --++ (0,-2) -- (8,0) --++(0,2) --++ (1,0);
\end{Diagramm}
\begin{Diagramm}{8}{4}{2}{$U_{GS_{2,3}}$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
\begin{Diagramm}{8}{4}{2}{$i_L$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}


\end{figure}


\end{document}
1
  • for star see if replacing \centering with \raggedleft gives satisfactory result.
    – Zarko
    Commented Oct 30, 2017 at 22:00

2 Answers 2

2

your approach to drawing has some draw backs, for example see what happens if you for the first diagram use

\begin{Diagramm}{8}{4}{2}{$U_{GS_{1,4}}(abcdefg)$}{0}
\draw [thick,red] (0,2) --++ (2,0) --++ (0,-2) -- (8,0) --++(0,2) --++ (1,0);
\end{Diagramm}

(it protrude out of right text margin). with another words, your approach works well, if the diagram labels aren't to wide.

let return me to your problem. I see three simple solutiona:

  • use suggestion in my comment below of your question:

    \begin{figure}
\raggedleft
\begin{Diagramm}{8}{4}{2}{$U_{GS_{1,4}}(abcdefg)$}{0}
\draw [thick,red] (0,2) --++ (2,0) --++ (0,-2) -- (8,0) --++(0,2) --++ (1,0);
\end{Diagramm}
\begin{Diagramm}{8}{4}{2}{$U_{GS_{2,3}}$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
\begin{Diagramm}{8}{4}{2}{$i_L$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
    \end{figure}
  • labels for y axis enclose to \llap{...}:

\Koordinatenkreuz{-.2}{10.3}{#5-0.2}{2.8}{$t$}{{\llap{#4}}};

and in figure environment use \centering. however, now will be centered diagrams without consideration of y axis

  • rotate labels with use of sloped options for node:

\newcommand{\Koordinatenkreuz}[6]{ % Für das Koordinatenkreuz, Änderungen hier betreffen ALLE Gitter im Latex Dokument
    \draw[->, >=latex, color=green!50!black] (#1,0) -- (#2,0) node[right] {#5};
    \draw[->, >=latex, color=green!50!black] (0,#3) -- 
                            node[minimum height=3ex,above,sloped] {#6}(0,#4); % <------
}

the last solution result is:

enter image description here

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations}
\newcommand{\Koordinatenkreuz}[6]{ % Für das Koordinatenkreuz, Änderungen hier betreffen ALLE Gitter im Latex Dokument
    \draw[->, >=latex, color=green!50!black] (#1,0) -- (#2,0) node[right] {#5};
    \draw[->, >=latex, color=green!50!black] (0,#3) --
                            node[minimum height=3ex,above,sloped] {#6}(0,#4); % <------
}

\newenvironment{Diagramm}[5]{
\begin{tikzpicture}%[trim axis left]
    \def\T{#1}
    \def\Thalf{#2}
    \def\DT{#3}
    \def\Label{#4}
    \def\Yrange{#5}
    %\Gitter{-.1}{10.1}{#5-0.1}{3.1}
    \Koordinatenkreuz{-.2}{10.3}{#5-0.2}{2.8}{$t$}{#4};
    \draw (#1,0) node[below]{$T$};
    \draw (#2,0) node[below]{$\frac{T}{2}$};
    \draw (#3,0) node[below]{$DT$};
}
{\end{tikzpicture}}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}
\centering
\begin{Diagramm}{8}{4}{2}{$U_{GS_{1,4}}$}{0}
\draw [thick,red] (0,2) --++ (2,0) --++ (0,-2) -- (8,0) --++(0,2) --++ (1,0);
\end{Diagramm}
\begin{Diagramm}{8}{4}{2}{$U_{GS_{2,3}}$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
\begin{Diagramm}{8}{4}{2}{$i_L$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
    \end{figure}
\end{document}

the second solution:

enter image description here

and the first solution:

enter image description here

enter image description here

i would consider the first or the third solution. however, rather your approach to drawing diagrams I would investigate possible solution with use of pgfplots:

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows, decorations}

\pgfplotsset{Diagram/.style={
            axis lines = left,
    xmax=9.5,
    ymax=1.5,
    xlabel = {$t$},
    xlabel style={at={(1,0)},anchor=west},
    ylabel style={at={(0,1)},rotate={-90},anchor=north east},
    ytick=\empty,
    no marks,
    every axis plot post/.append style={very thick, red},
                    }% end of Diagram style
            }% end of pgfplotsset

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}
    \pgfplotsset{xticklabels={ , , DT, T/2, , T},
                 height=4cm, width=0.8\textwidth}
\centering
    \begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram,
    ylabel = $U_{GS_{1,4}}$,
            ]
\addplot coordinates {(0,1)  (2,1) (2,0)  (8,0)  (8,1) (9,1)};
\end{axis}
\end{tikzpicture}

    \begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram,
    ylabel = $U_{GS_{2,3}}$,
            ]
\addplot coordinates {(0,0)  (4,0)  (4,1)  (6,1) (6,0) (9,0)};
\end{axis}
\end{tikzpicture}

    \begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram,
    ylabel = $i_L$,
            ]
\addplot coordinates {(0,0)  (4,0)  (4,1)  (6,1) (6,0) (9,0)};
\end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

addendum: another simple solutios is move y axis label on the inner side of diagram :-) :

enter image description here

additional lines (for example for average value of variable) can be draw using "pure" tikz syntax like \draw[<line specification>] (0,0.35) -- (9,0.35):.

code for above image is:

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows, decorations}

\pgfplotsset{Diagram/.style={
            axis lines = left,
    xmin=0, xmax=9.5,
    ymin=0, ymax=1.8,
    xlabel = {$t$},
    xlabel style={at={(1,0)},anchor=west},
    ylabel style={at={(0,1)},rotate={-90},anchor=north west},
    ytick=\empty,
    no marks,
    every axis plot post/.append style={very thick, red},
                    }% end of Diagram style
            }% end of pgfplotsset

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}
    \pgfplotsset{xticklabels={ , , DT, T/2, , T},
                 height=4cm, width=0.8\textwidth}
\centering
    \begin{tikzpicture}%[trim axis left]
\begin{axis}[Diagram,
    ylabel = $U_{GS_{1,4}}$,
            ]
\addplot coordinates {(0,1)  (2,1) (2,0)  (8,0)  (8,1) (9,1)};
\end{axis}
\end{tikzpicture}

    \begin{tikzpicture}%[trim axis left]
\begin{axis}[Diagram,
    ylabel = $U_{GS_{2,3}}$,
            ]
\addplot coordinates {(0,0)  (4,0)  (4,1)  (6,1) (6,0) (9,0)};
\end{axis}
\end{tikzpicture}

    \begin{tikzpicture}%[trim axis left]
\begin{axis}[Diagram,
    ylabel = $i_L$,
            ]
\addplot coordinates {(0,0)  (4,0)  (4,1)  (6,1) (6,0) (9,0)};
\draw[ultra thin] (0,0.35) --  ++ (9,0);
\end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}
4
  • Thanks a lot. I'm going for the pgfplot solution since it allows me to define these axis easily and later, when I've generated data I'll need to use pgpfplots anyway. One additional question: I tried setting the line width to "ultra thin" by adding another \addplot [ultra thin] coordinates {(0,0.7),(9,0.7)}; underneath the i_L diagram. However the lines still appear the same?
    – SF6
    Commented Oct 31, 2017 at 12:15
  • unfortunately you can't override global setting of line width (used in addplot) with local one. a solution for this particular case can be \draw[ultra thin] (0,0.7) -- (9,0.7);.
    – Zarko
    Commented Oct 31, 2017 at 12:36
  • @SF6, see the addendum to my answer.
    – Zarko
    Commented Oct 31, 2017 at 13:47
  • @SF, i see that you use my answer as basis for your new questions :-). so i thing it is time to vote and accept it, isn't it?
    – Zarko
    Commented Nov 1, 2017 at 15:09
3

One way to align the diagrams properly is to put everything in one tikzpicture and use scope environments with vertical offsets.

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}

%\newcommand{\Gitter}[4]{ % Für die Gitterliniene, Änderungen hier betreffen ALLE Gitter %im Latex Dokument
%    \draw[very thin,color=gray] (#1,#3) grid (#2,#4);
%}

\newcommand{\Koordinatenkreuz}[6]{ % Für das Koordinatenkreuz, Änderungen hier betreffen ALLE Gitter im Latex Dokument
        \draw[->, >=latex, color=green!50!black] (#1,0) -- (#2,0) node[right] {#5};
        \draw[->, >=latex, color=green!50!black] (0,#3) -- (0,#4) node[left] {#6};
}

\newenvironment{Diagramm}[6][]{ 
\begin{scope}[#1]
        \def\T{#2}
        \def\Thalf{#3}
        \def\DT{#4}
        \def\Label{#5}
        \def\Yrange{#6}

        %\Gitter{-.1}{10.1}{#5-0.1}{3.1}
        \Koordinatenkreuz{-.2}{10.3}{#6-0.2}{2.8}{$t$}{#5};
        \draw (#2,0) node[below]{$T$};
        \draw (#3,0) node[below]{$\frac{T}{2}$};
        \draw (#4,0) node[below]{$DT$};
}
{\end{scope}}

\begin{document}

% {T}{T/2}{DT}{y-Label}{negative y-range}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{Diagramm}{8}{4}{2}{$U_{GS_{1,4}}$}{0}
\draw [thick,red] (0,2) --++ (2,0) --++ (0,-2) -- (8,0) --++(0,2) --++ (1,0);
\end{Diagramm}
\begin{Diagramm}[yshift=-4cm]{8}{4}{2}{$U_{GS_{2,3}}$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
\begin{Diagramm}[yshift=-8cm]{8}{4}{2}{$i_L$}{0}
\draw [thick,red] (0,0) -- (4,0) --++ (0,2) --++ (2,0) --++(0,-2) -- (9,0);
\end{Diagramm}
\end{tikzpicture}
\end{figure}

\end{document}
1
  • Thanks, will do some reading on the scope environment. For now, I'm using the suggestions posted by Zarko.
    – SF6
    Commented Nov 1, 2017 at 21:43

You must log in to answer this question.

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