4

Basically this question (Align vertically two tikzpicture in subfloat) but for vertically placed subfloats.

I know you can align them with the baseline option if they're next to each other, but I don't know how I can align them horizontally.

I'd like the dashed lines to be vertical, i.e. by aligning the nodes.

I'd like the dashed lines to be vertical, i.e. by aligning the nodes.

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\centering
\newcommand{\length}{400}
\subfloat[Bovenaanzicht]{
    \begin{tikzpicture}[x=.250mm,y=.250mm,remember picture]
    % Afmeting van inlet
    \draw[<->] (0, 45) -- (0, -45) node[left,midway] {90mm};
    % Afmeting outlet
    \draw[<->] (\length + 40, 45) -- (\length + 40, -45) node[right,midway] {90mm};
    % Afmeting fan
    \draw[<->] (65, .5*65) -- (65, -.5*65) node[left,midway] {65mm};

    % Tube
    \draw (0,45) -- (65, 0.5*65) -- (65+42, 0.5*65) -- (\length, 45);
    \draw (0,-45) -- (65, -0.5*65) -- (65+42, -0.5*65) -- (\length, -45);
    \node (fanpositionl bovenaanzicht) at (65, 0.5*65){};
    \node (fanpositionr bovenaanzicht) at (65+42, 0.5*65){};
    \end{tikzpicture}
}
\par
\subfloat[Zijaanzicht]{
    \begin{tikzpicture}[x=.250mm,y=.250mm,remember picture]
    % Tube
    \draw (0,37) -- (65, 65) -- (65+42, 65) -- (\length, 32);
    \draw (0,0) -- (\length, 0);
    \node (fanpositionl zijaanzicht) at(65, 0) {};
    \node (fanpositionr zijaanzicht) at(65+42, 0) {};
    \end{tikzpicture}
}
\begin{tikzpicture}[x=.250mm,y=.250mm,overlay,remember picture]
\draw[dashed] (fanpositionl zijaanzicht) -- (fanpositionl bovenaanzicht);
\draw[dashed] (fanpositionr zijaanzicht) -- (fanpositionr bovenaanzicht);
\end{tikzpicture}
\caption{Profiel van ``Elliptische'' duct}\label{fig:motorschacht_elliptisch}
\end{figure}
\end{document}
  • Welcome to TeX.SX! Please complete your code snippet to a minimal working example (MWE) showing the documentclass and how you load the relevant packages. – Andrew Swann Feb 21 '15 at 12:16
  • Edited it for being a MWE. – rubdos Feb 21 '15 at 12:58
2

You need to make the pictures appear to be of the same size to tikz. This can be done by setting the bounding box completely, or partially via trim left and trim right.

Sample output

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{figure}
\centering
\newcommand{\length}{280}
\subfloat[Bovenaanzicht]{
  \begin{tikzpicture}[x=.250mm,y=.250mm,trim left,trim right=200,
    remember picture]
    % Afmeting van inlet
    \draw[<->] (0, 45) -- (0, -45) node[left,midway] {90mm};
    % Afmeting outlet
    \draw[<->] (\length + 40, 45) -- (\length + 40, -45)
      node[right,midway] {90mm};
    % Afmeting fan
    \draw[<->] (65, .5*65) -- (65, -.5*65) node[left,midway] {65mm};

    % Tube
    \draw (0,45) -- (65, 0.5*65) -- (65+42, 0.5*65) -- (\length, 45);
    \draw (0,-45) -- (65, -0.5*65) -- (65+42, -0.5*65) -- (\length, -45);
    \node (fanpositionl bovenaanzicht) at (65, 0.5*65){};
    \node (fanpositionr bovenaanzicht) at (65+42, 0.5*65){};
    \end{tikzpicture}
}\\
\subfloat[Zijaanzicht]{
\begin{tikzpicture}[x=.250mm,y=.250mm,trim left,trim right=200,
  remember picture]
  % Tube
  \draw (0,37) -- (65, 65) -- (65+42, 65) -- (\length, 32);
  \draw (0,0) -- (\length, 0);
  \node (fanpositionl zijaanzicht) at(65, 0) {};
  \node (fanpositionr zijaanzicht) at(65+42, 0) {};
\end{tikzpicture}
}
\begin{tikzpicture}[x=.250mm,y=.250mm,remember picture,overlay]
\draw[dashed] (fanpositionl zijaanzicht) -- (fanpositionl bovenaanzicht);
\draw[dashed] (fanpositionr zijaanzicht) -- (fanpositionr bovenaanzicht);
\end{tikzpicture}
\caption{Profiel van ``Elliptische'' duct}\label{fig:motorschacht_elliptisch}
\end{figure}


\end{document}

I have reduced your \length variable so the pictures fit on the page.

  • The problem indeed was that the left hand size of the first subpicture had negative x values for some points and lines. Adding the same things to the second picture "solved" the issue. I also added the trim left parameter for the tikzpicture's, now it seems solved. Thank you! – rubdos Feb 21 '15 at 15:40
  • You can write trim left=-10 or whatever too. trim left on its own is just a short-hand for trim left=0 – Andrew Swann Feb 21 '15 at 15:56
2

The problem is that the first image is wider than \textwidth so it protrudes into the right margin. To prevent this, one option is to scale down your tikzpictures (I used scale=0.85). Also, notice that you had some spurious blank spaces that I killed in my code using %:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{pgfplots}
\usetikzlibrary{positioning}

\begin{document}

\begin{figure}
\centering
\newcommand{\length}{400}
\subfloat[Bovenaanzicht]{%
    \begin{tikzpicture}[x=.250mm,y=.250mm,remember picture,scale=0.85]
    % Afmeting van inlet
    \draw[<->] (0, 45) -- (0, -45) node[left,midway] {90mm};
    % Afmeting outlet
    \draw[<->] (\length + 40, 45) -- (\length + 40, -45) node[right,midway] {90mm};
    % Afmeting fan
    \draw[<->] (65, .5*65) -- (65, -.5*65) node[left,midway] {65mm};

    % Tube
    \draw (0,45) -- (65, 0.5*65) -- (65+42, 0.5*65) -- (\length, 45);
    \draw (0,-45) -- (65, -0.5*65) -- (65+42, -0.5*65) -- (\length, -45);
    \node (fanpositionl bovenaanzicht) at (65, 0.5*65){};
    \node (fanpositionr bovenaanzicht) at (65+42, 0.5*65){};
    \end{tikzpicture}%
}
\par
\subfloat[Zijaanzicht]{%
    \begin{tikzpicture}[x=.250mm,y=.250mm,remember picture,scale=0.85]
    % Tube
    \draw (0,37) -- (65, 65) -- (65+42, 65) -- (\length, 32);
    \draw (0,0) -- (\length, 0);
    \node (fanpositionl zijaanzicht) at(65, 0) {};
    \node (fanpositionr zijaanzicht) at(65+42, 0) {};
    \end{tikzpicture}%
}
\begin{tikzpicture}[x=.250mm,y=.250mm,overlay,remember picture]
\draw[dashed] (fanpositionl zijaanzicht) -- (fanpositionl bovenaanzicht);
\draw[dashed] (fanpositionr zijaanzicht) -- (fanpositionr bovenaanzicht);
\end{tikzpicture}
\caption{Profiel van ``Elliptische'' duct}\label{fig:motorschacht_elliptisch}
\end{figure}

\end{document}

enter image description here

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.