如何交叉引用使用 adjustwidth 的表格?

如何交叉引用使用 adjustwidth 的表格?

我设置了一个环境,并通过从包中将table其向左移动了一点。但是,如果我想通过从包中引用它,编译后,会显示“??”而不是引用。我在下面的最小示例中做错了什么?请注意,注释掉环境后就会出现正确的标签。adjustwidthchangepage\crefcleverefadjustwidth

\documentclass{article}
\usepackage{changepage}
\usepackage{cleveref}
\usepackage{multirow}
\begin{document}
\begin{table}[!ht]                                                                                                                      
    \begin{adjustwidth}{-2.5in}{0in}
        \centering
        \caption{caption}
        \begin{tabular}{|l|l|}
            \hline
            \multirow{2}{*}{first two rows} & 1 \\
            & 2 \\
            \hline
            third row & 3 \\
            \hline
        \end{tabular}                                                                                                                   
    \end{adjustwidth} 
    \label{label}                                                                                                                       
\end{table}
Here, I want to reference it: \cref{label}.
\end{document}

答案1

您发label错地方了,请立即移动\caption

\documentclass{article}
\usepackage{changepage}
\usepackage{multirow}
\usepackage{cleveref}

\begin{document}
\begin{table}[!ht]
    \begin{adjustwidth}{-2.5in}{0in}
        \centering
        \caption{caption}
        \label{label}
        \begin{tabular}{|l|l|}
            \hline
            \multirow{2}{*}{first two rows} & 1 \\
            & 2 \\
            \hline
            third row & 3 \\
            \hline
        \end{tabular}
    \end{adjustwidth}
\end{table}
Here, I want to reference it: \cref{label}.
\end{document}

在此处输入图片描述

编辑:

顺便说一句,您的设置adjustwidth导致其内容超出页面左侧。您需要减少它,例如,如下一个 MWE 中的第二个示例所示:


\documentclass{article}
\usepackage{changepage}
\usepackage{multirow}
\usepackage{cleveref}

%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\begin{document}
\lipsum[11]

\begin{table}[!ht]
    \begin{adjustwidth}{-2in}{}
        \centering
        \caption{\lipsum[66]}
        \label{label}
        \begin{tabular}{|l|l|}
            \hline
            \multirow{2}{*}{first two rows} & 1 \\
            & 2 \\
            \hline
            third row & 3 \\
            \hline
        \end{tabular}
        
\rule{\linewidth}{1pt}
    \end{adjustwidth}
\end{table}
Here, I want to reference it: \cref{label}.
\begin{table}[!ht]
    \begin{adjustwidth}{-\dimexpr\oddsidemargin+\marginparwidth}{}
        \centering
        \caption{\lipsum[66]}
        \label{label}
        \begin{tabular}{|l|l|}
            \hline
            \multirow{2}{*}{first two rows} & 1 \\
            & 2 \\
            \hline
            third row & 3 \\
            \hline
        \end{tabular}
        
\rule{\linewidth}{1pt}
    \end{adjustwidth}
\end{table}
\end{document}

在此处输入图片描述

(红线表示页面布局)

相关内容