1

Why does simply loading the hyperref package mess up the alignment and how can I solve this?

Correct image and sample code:

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage[margin=0pt,singlelinecheck=0,labelfont=bf]{subfig}
\usepackage{graphicx}
\graphicspath{{Bilder/}}
\usepackage[hidelinks]{hyperref}
\begin{document}
\begin{figure}[hbt]
\begin{tabularx}{\textwidth}{>{\raggedleft \arraybackslash}X
                         >{\raggedright\arraybackslash}X}
\subfloat[]{\label{fig-a}\includegraphics[width=0.3\textwidth]{1.png}}
&   \subfloat[]{\label{fig-b}\includegraphics[width=0.2\textwidth]    {1.png}}
\\%
\subfloat[]{\label{fig-c}\includegraphics[width=0.2\textwidth]{1.png}}
&   \subfloat[]{\label{fig-d}\includegraphics[width=0.22\textwidth]{1.png}}
\end{tabularx}
\caption{}%
\label{}
\end{figure}
\end{document}

Misalignment due to hyperref:

enter image description here

2

It seems that \hyperref forces alignment of cell content according to its own standards. In the case of tabular, this means cell content will be top aligned. This doesn't matter, when the images included by \includegraphics{...} have the same height...

In your case, however, the images have different heights. If you prefer them to be bottom aligned, then the simplest cure is to redefine the X column:

\renewcommand\tabularxcolumn[1]{b{#1}}

which will result in:

enter image description here

The complete code for getting the MWE as above is:

\documentclass{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{b{#1}}
\usepackage{graphicx}
%\graphicspath{{Bilder/}}

\usepackage[margin=0pt,singlelinecheck=0,labelfont=bf]{subfig}
\usepackage[hidelinks]{hyperref}

\begin{document}
\begin{figure}[hbt]
\begin{tabularx}{\textwidth}{>{\raggedleft \arraybackslash}X
                             >{\raggedright\arraybackslash}X}
\subfloat[\label{fig-a}]{\includegraphics[width=0.3\textwidth]{example-image}}
&   \subfloat[\label{fig-b}]{\includegraphics[width=0.2\textwidth]    {example-image}}
\\%
\subfloat[\label{fig-c}]{\includegraphics[width=0.2\textwidth]{example-image}}
&   \subfloat[\label{fig-d}]{\includegraphics[width=0.22\textwidth]{example-image}}
\end{tabularx}
\caption{}%
\label{}
\end{figure}
\end{document}

If, however, you'd like to have the bottom images aligned at the top, but keep the top images aligned at the bottom (see Addendum 2 in my answer to your question) you can employ the package \adjustwidth:

\documentclass{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{b{#1}}
\usepackage{graphicx}
%\graphicspath{{Bilder/}}

\usepackage[export]{adjustbox}
\usepackage[margin=0pt,singlelinecheck=0,labelfont=bf]{subfig}
\usepackage[hidelinks]{hyperref}

\begin{document}
\begin{figure}[hbt]
\begin{tabularx}{\textwidth}{>{\raggedleft \arraybackslash}X
                             >{\raggedright\arraybackslash}X}
\subfloat[\label{fig-a}]{\includegraphics[width=0.3\textwidth]{example-image}}
&   \subfloat[\label{fig-b}]{\includegraphics[width=0.2\textwidth]    {example-image}}
\\%
\subfloat[\label{fig-c}]{\includegraphics[width=0.2\textwidth,valign=T]{example-image}}
&   \subfloat[\label{fig-d}]{\includegraphics[width=0.22\textwidth,valign=T]{example-image}}
\end{tabularx}
\caption{}%
\label{}
\end{figure}
\end{document}

in order to get:

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.