如何抑制:表格中的旋转标题自动调整行高以适应文本长度

如何抑制:表格中的旋转标题自动调整行高以适应文本长度

我有一张图片及其标题。我想将标题放在侧面,如问题所示“如何单独旋转图形的标题”,但问题是我无法设置行高。我希望标题文本以块的形式对齐,其长度由页面高度或图像的预期高度决定(见下图)。

这是唯一的使用方法吗\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}

在此处输入图片描述

答案1

将单元格内容放在表格环境中将使内容垂直和水平居中。

定义新的列类型(\newcolumntypearray)可以控制单元格的宽度。在第一个表格级别中,控制标题单元格的宽度;在第二个表格级别(因为是旋转的)中,控制标题单元格的高度。

类型W设置一个内容居中的单元格,类型Hraggedright内容一致。

对图像高度和标题使用相同的长度可以简化设置,如下所示:

\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<<<<<<<<<<<<<<<

使用文本区域的全部高度

A

改变标题的对齐方式、宽度和高度。

b

(数字计数器自动增加,\refstepcounter{figure}不需要)

\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}

相关内容