1

I want to align two vertically arranged tikz plots relative to their right boundary. They both contain a coordinate system - e.g., a Bode diagram. Due to different y labels and ticks, they have different widths. Thus centering them, the x-axis are not vertically aligned. I can adjust it manually by adjusting the height of the figures and using a \hfill in combination with a minipage:

\begin{figure}[htb]
  \centering
  \begin{subfigure}[b]{0.95\textwidth}
    \centering
    \includegraphics[height=6cm]{plot1}%
  \begin{minipage}{.5cm}
            \hfill
  \end{minipage}
    \caption{}
    \label{fig:plot1}
  \end{subfigure}

  \begin{subfigure}[b]{0.95\textwidth}
    \centering
    \includegraphics[height=6cm]{plot2}
    \caption{}
    \label{fig:plot2}
  \end{subfigure}
  \caption{}
  \label{fig:plots}
\end{figure}

This is not very robust, as it relies on the figures having the same raw height. If not, there's a lot of try and error involved... Is there a way to do this more elegant and robust using the subcaption package, e.g., similar to anchor=east functionality available in tikz?

Thanks in advance!

1

Something like this? It's a solution that uses a minipage inside the figure environment, and everything inside the minipage (basically, two subfigure environments) is typeset ragged-left (aka flushright).

enter image description here

\documentclass[demo]{article} % remove 'demo' option in real doc.
\usepackage{subcaption,graphicx}

\begin{document}
\begin{figure}[htb]
  \centering
  \begin{minipage}{0.9\textwidth}
  \raggedleft % <-- new
  \begin{subfigure}{1\textwidth}
    \includegraphics[width=\textwidth]{plot1}
    \caption{}
    \label{fig:plot1}
  \end{subfigure}

  \bigskip
  \begin{subfigure}{0.8\textwidth}
    \includegraphics[width=\textwidth]{plot2}
    \caption{}
    \label{fig:plot2}
  \end{subfigure}
  \end{minipage}
  \caption{}
  \label{fig:plots}
\end{figure}
\end{document}
  • Hi, that seems to go into the right direction. Thanks! However, if I use \includegraphics[height=6cm], the alignment gets lost. – sts Apr 17 '18 at 10:13
  • @sts - I'm not sure I follow your comment. Did you add the option \includegraphics[height=6cm] to the exisiting option, or did you replace width=\textwidth with \includegraphics[height=6cm]? In the former case, the right-alignment should be preserved. Please be specific as to what you're doing. – Mico Apr 17 '18 at 11:26
  • I replaced \includegraphics[width=\textwidth]{plot*} with \includegraphics[height=6cm]{plot*}. – sts Apr 18 '18 at 13:25

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.