0

I have a image and its caption. I would like to put the caption sideways as it is shown in the question "how-to-rotate-exclusively-the-caption-of-a-figure", but the problem is that I am not able to set row height. I would like to have the caption text to be aligned in a block with its length, determined by the height of the page or the expected height of the image (see figure below).

Is here only way to use \parbox?

MNWE:

\documentclass{scrbook}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\usepackage{tabularx}

\begin{document} \begin{figure} \refstepcounter{figure} \begin{tabularx}{\linewidth}{|c|c|} \hline \ \includegraphics[width=0.2\linewidth, height=0.2\textheight,keepaspectratio]{example-image-a} & \rotatebox{90}{Obrázek~\thefigure: Long dummy text that can't be wrapped} \ \hline \end{tabularx} \end{figure} \end{document}

enter image description here

JardaFait
  • 3,922

1 Answers1

1

Putting cell content within a tabular environment will center the content both vertically and horizontally.

The definition of new types of columns (\newcolumntype package array) allows to control the width of the cells. In the first tabular level, the width of the caption cell, in the second tabular level --because it is rotated--, the height of the caption cell.

Type W sets a cell with centered content, type H with raggedright content.

Using the same length for both the image height and the caption simplifies the setup, as in:

\begin{tabular}{c}\includegraphics[height=0.2\textheight, keepaspectratio]{example-image-a}\end{tabular} &
            \rotatebox{90}{\begin{tabular}{H{0.2\textheight}} % height of caption<<<<<<<<<<<<<<<

Using the full height of the text area

a

Changing alignment, width and height of the caption.

b

(The figure counter increments automatically, \refstepcounter{figure} is not needed)

\documentclass{scrbook}
%%\usepackage[export]{adjustbox}
\usepackage{graphicx}
%%\usepackage{tabularx}

\usepackage{array}%\newcolumntype <<<<<<

\begin{document}

\newcolumntype{W}[1]{ >{\centering\arraybackslash} m{#1}}% caption row centered \newcolumntype{H}[1]{ >{\raggedright\arraybackslash} m{#1}} % caption row raggedright \setlength{\extrarowheight}{1ex}%vertical padding

\begin{figure*}

% \refstepcounter{figure} \begin{tabular}{|c|W{1cm}|}% width of caption <<<<<<<<<<<<<<< \hline \begin{tabular}{c}\includegraphics[width=0.3\linewidth, keepaspectratio]{example-image-a}\end{tabular} & \rotatebox{90}{\begin{tabular}{W{\textheight}} % height of caption <<<<<<<<<<<<<<< Obrázek~\thefigure: Long dummy text that can't be wrapped \
\end{tabular}}\ \hline
\end{tabular} \end{figure*}

\begin{figure} % \refstepcounter{figure} % not needed <<<<<<<<<< \begin{tabular}{|c|W{3cm}|} % width of caption <<<<<<<<<<<<<<< \hline \begin{tabular}{c}\includegraphics[width=0.3\linewidth, keepaspectratio]{example-image-a}\end{tabular} & \rotatebox{90}{\begin{tabular}{W{4cm}} %height of caption Obrázek~\thefigure: Long dummy text that can't be wrapped \
\end{tabular}}\ \hline
\end{tabular} \end{figure
}

\begin{figure} % \refstepcounter{figure}% not needed \begin{tabular}{|c|W{2cm}|}% width of caption <<<<<<<<<<<<<<< \hline \begin{tabular}{c}\includegraphics[width=0.3\linewidth, keepaspectratio]{example-image-a}\end{tabular} & \rotatebox{90}{\begin{tabular}{H{4cm}} % height of caption<<<<<<<<<<<<<<< Obrázek~\thefigure: Long dummy text that can't be wrapped \
\end{tabular}}\ \hline
\end{tabular} \end{figure
}

\end{document}

Simon Dispa
  • 39,141