3

I would like to position some grafics in an special order and layout. I try to seperate one "column" using vrule

as you can see here, the vrule is not aligned on both positions, but for me the width settings of both "rows" looks like the same.

not aligned

here is the code I'm using:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}

\begin{document}

\begin{figure} [h]
  \centering\renewcommand{\thesubfigure}{a}
  \subfloat[A Text]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}
  \hspace{0.03\textwidth} \renewcommand{\thesubfigure}{b}
  \subfloat[B Text]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}
  \hspace{0.03\textwidth} \vrule\ \hspace{0.015\textwidth} \renewcommand{\thesubfigure}{e} 
  \subfloat[E Text]{
    \includegraphics[width=0.28\textwidth]
     {example-image}}

     \renewcommand{\thesubfigure}{c}
  \subfloat[C Text]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}
  \hspace{0.03\textwidth}\renewcommand{\thesubfigure}{d}
  \subfloat[D Text]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}
  \hspace{0.03\textwidth} \vrule\ \hspace{0.015\textwidth} \renewcommand{\thesubfigure}{f} 
  \subfloat[F Text]{
     \includegraphics[width=0.28\textwidth]
     {example-image}}

  \captionof{figure}[]{A-F Text}
\end{figure}

\end{document}

any suggestions why it is not aligned?

9
  • 1
    It would be much easier to debug if you provided a test document that demonstrated the issue. You can use example-image as the image, which is in distributions for that use. May 8, 2017 at 19:00
  • Addition to @DavidCarlisle 's comment. See here for pre-installed example images: tex.stackexchange.com/questions/231738 May 8, 2017 at 19:06
  • The code is not compilable because it's a fragment only
    – user31729
    May 8, 2017 at 19:07
  • I changed it to example-image
    – flor1an
    May 8, 2017 at 19:08
  • @user2798895: Yes, but it's no document we can compile
    – user31729
    May 8, 2017 at 19:12

2 Answers 2

1

You have to take care to not insert unwanted spaces in your code. They where the reason for the wrong alignment. I inserted some % to ensure that there are non at the end of each line.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}

\begin{document}
\begin{figure} [h]

\centering\renewcommand{\thesubfigure}{a}%
\subfloat[A Text]{%
    \includegraphics[width=0.28\textwidth]%
    {example-image}}%
\hspace{0.03\textwidth}\renewcommand{\thesubfigure}{b}%
\subfloat[B Text]{%
    \includegraphics[width=0.28\textwidth]%
    {example-image}}%
\hspace{0.03\textwidth}\vrule\
\hspace{0.015\textwidth}\renewcommand{\thesubfigure}{e}%
\subfloat[E Text]{%
    \includegraphics[width=0.28\textwidth]%
    {example-image}}%

\renewcommand{\thesubfigure}{c}%
\subfloat[C Text]{%
    \includegraphics[width=0.28\textwidth]%
    {example-image}}%
\hspace{0.03\textwidth}\renewcommand{\thesubfigure}{d}%
\subfloat[D Text]{%
    \includegraphics[width=0.28\textwidth]%
    {example-image}}%
\hspace{0.03\textwidth}\vrule\
\hspace{0.015\textwidth}\renewcommand{\thesubfigure}{f}%
\subfloat[F Text]{%
    \includegraphics[width=0.28\textwidth]%
    {example-image}}%

\captionof{figure}[]{A-F Text}

\end{figure}
\end{document}

I think an easier solution would be to use a tabular to take care of the alignment, spacing and vertical rule.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}

\begin{document}
\begin{figure} [h]

\begin{tabular}{c c | c}
    \subfloat[A Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
    \subfloat[B Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
    \subfloat[C Text]{\includegraphics[width=0.28\textwidth]{example-image}} \\
    \subfloat[D Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
    \subfloat[E Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
    \subfloat[F Text]{\includegraphics[width=0.28\textwidth]{example-image}} \\
\end{tabular}
\captionof{figure}[]{A-F Text}

\end{figure}
\end{document}
1

I suggest a different approach, similar to Georg's, but that avoids the need of juggling with counters.

Nesting tabulars will ensure correct numbering.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}

\begin{document}

\begin{figure}[htp] % <--- not only h
\centering

\begin{tabular}{@{}c|c@{}}
\begin{tabular}{@{}cc@{}}
\subfloat[A Text]{%
  \includegraphics[width=0.28\textwidth]{example-image}%
}
&
\subfloat[B Text]{%
  \includegraphics[width=0.28\textwidth]{example-image}%
}
\\
\subfloat[C Text]{%
  \includegraphics[width=0.28\textwidth]{example-image}%
}
&
\subfloat[D Text]{%
  \includegraphics[width=0.28\textwidth]{example-image}%
}
\end{tabular}
&
\begin{tabular}{@{}c@{}}
\subfloat[E Text]{%
  \includegraphics[width=0.28\textwidth]{example-image}%
}
\\
\subfloat[F Text]{%
  \includegraphics[width=0.28\textwidth]{example-image}%
}
\end{tabular}
\end{tabular}

\caption{A-F Text}

\end{figure}

\end{document}

enter image description here

You must log in to answer this question.

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