如何将 tabularx 结果置于“图形”环境中

如何将 tabularx 结果置于“图形”环境中
\documentclass[
    pdftex,
    a4paper,
    11pt,
    oneside,
%   fleqn,          % auskommentiert um equations zu zentrieren
    listof=totoc,
    headlines=2.1,
    headsepline,
    numbers=noenddot,
    hyphens,
]{scrreprt}
\usepackage[pdftex]{graphicx}
\usepackage{tabularx}
\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=10cm]{picture.PNG}
    \caption{My caption is here}
    \begin{tabularx}{\textwidth}{p{2cm} p{\textwidth}}
        $m$:& my explanation for this variable is quite long\\
        $y$:& here another
    \end{tabularx}  
\end{figure}
\end{document}

结果

在实际文档中,我有一张包含许多变量的图片。为了清楚起见,我想在图片下方的某种列表中解释它们。我希望将这个列表居中。

提前谢谢了

答案1

如果您使用正确的参数,您的表格将完美地位于图形下方的中心,如下面的第一个代码所示。但是我建议另一种方法:使用measuredfigure包中的环境threeparttable,您的解释将具有与图形完全相同的宽度。此外,我认为description通过以下方式定制的环境enumitem将产生更好的解决方案:

\documentclass[
    a4paper,
    11pt,
    oneside,
% fleqn, % auskommentiert um equations zu zentrieren
    listof=totoc,
    headlines=2.1,
    headsepline,
    numbers=noenddot,
    hyphens,
]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{enumitem} 

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=10cm]{picture.PNG}
    \caption{My caption is here}\medskip
    \begin{tabularx}{\linewidth}{|p{2cm}|X|}
        $m$:& my explanation for this variable is quite long\\
        $y$:& here another
    \end{tabularx}
\end{figure}

\begin{figure}
\centering
\begin{measuredfigure}
    \centering
    \includegraphics[width=10cm]{picture.PNG}
    \caption{My caption is here}\medskip
    \begin{description}[labelwidth=2cm, leftmargin=2cm, labelsep=0pt, itemsep=0pt, font=\itshape]
        \item[$m$:] my explanation for this variable is very very very long
       \item[$y$:] here another
    \end{description}
\end{measuredfigure}
\end{figure}

\end{document} 

在此处输入图片描述

答案2

在此处输入图片描述

红线表示文本边框。我只改变p{\textwidth}L类型,它源自X类型:

\documentclass[
    pdftex,
    a4paper,
    11pt,
    oneside,
%   fleqn,          % auskommentiert um equations zu zentrieren
    listof=totoc,
    headlines=2.1,
    headsepline,
    numbers=noenddot,
    hyphens,
]{scrreprt}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=10cm]{picture.PNG}
    \begin{tabularx}{\textwidth}{p{2cm} L}
        $m$:    & my explanation for this variable is quite long \dots my explanation for this variable is quite long\\
        $y$:    & here another
    \end{tabularx}
    \caption{My caption is here}
\end{figure}
\end{document}

或者

\documentclass[
    pdftex,
    a4paper,
    11pt,
    oneside,
%   fleqn,          % auskommentiert um equations zu zentrieren
    listof=totoc,
    headlines=2.1,
    headsepline,
    numbers=noenddot,
    hyphens,
]{scrreprt}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=10cm]{picture.PNG}

    \medskip\small
    \begin{tabularx}{10cm}{p{1cm} L} % <-- table has the same width as image
    \multicolumn{2}{l}{\textbf{Legend}} \\
        $m$:    & my explanation for this variable is quite long \dots my explanation for this variable is quite long \\
        $y$:    & here another
    \end{tabularx}
    \caption{My caption is here}
\end{figure}
\end{document}

这使

在此处输入图片描述

相关内容