如何在单个表格列中将 \nameref 文本拆分到两行?

如何在单个表格列中将 \nameref 文本拆分到两行?

我有下表

\documentclass{article}
\usepackage[english]{babel}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{amsfonts}
\usepackage[a4paper,layout=a4paper,
        bindingoffset=4cm,left=0cm,right=2cm,
        head=2.5cm, bmargin=2cm]{geometry} 
\usepackage{microtype}            
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{url} 
\usepackage[round]{natbib}
\usepackage{listings}
\usepackage{booktabs}  
\usepackage{multirow} 
\RequirePackage[l2tabu, orthodox]{nag}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows, shapes, chains, fit, backgrounds, calc, decorations.pathreplacing, matrix, calligraphy, positioning}
\usepackage{hyperref}
\usepackage[flushleft]{threeparttable}
\usepackage[inline, shortlabels]{enumitem} 
\usepackage{tikzlings}
\usepackage{array}
\usepackage{rotating}
\usepackage{subcaption}
\usepackage{cleveref}    

% try and get a lower case first letter for the section hyperlinks working
\newcommand{\lnameref}[1]{%
\bgroup
\let\nmu\MakeLowercase
\nameref{#1}\egroup}
\newcommand{\fnameref}[1]{%
\bgroup
\def\nmu{\let\nmu\MakeLowercase}%
\nameref{#1}\egroup}
\newcommand{\nmu}{}

\begin{document}

\begin{table}[htbp]
\begin{threeparttable}
\tabcolsep=0.1cm
\begin{tabular}{l | l | l | l | l}
    \toprule
    \multirow{2}{*}{\nameref{ssec:Sx}} & \multirow{2}{*}{Age-group} & Partnership & Usual resident & Hours worked in \\
    & & status & in household\tnote{1} & employment per week\\
    \midrule 
    \addlinespace
    Male & 0-4 years & \nameref{ssec:Prtnrd} & One usual resident & 1-9 hours \\ 
    Female & 5-9 years & Non-partnered & Two usual residents & 10-19 hours \\
    & 10-14 years & NEI\tnote{2} & Three usual residents & 20-29 hours \\ 
    & 15-17 years & & Four usual residents & 30-39 hours \\ 
    & 18-24 years & & Five usual residents & 40-49 hours \\
    & 25-34 years & & Six usual residents & 50 hours or more \\ 
    & 35-44 years & & Seven usual residents & Not working\\ 
    & 45-54 years & & Eight or More & NEI\tnote{3} \\ 
    & 55-64 years & & & \\ 
    & 65-74 years & & & \\ 
    & 85 Years \& Over & & & \\
          
\end{tabular}
\begin{tablenotes}
    \footnotesize
    \item[1] The count of individuals in the household was collected on the separate Dwellings Form, but the information on each individual was collected on the Individual Form.
    \item[2] An aggregate of the residual categories. These categories included ``response unidentifiable", ``not stated", and ``refused to answer". All children in the age groups 0-4 years, 5-9 years, and 10-14 years were coded to this personal relationship category by Stats NZ.
    \item[3] An aggregate of the residual categories. These categories included ``Don't know", ``Refused to answer", ``Response unidentifiable", ``Response outside scope", and ``Not stated". Non-response was coded to ``Not stated" unless the respondent clearly indicated they refused to answer the question. All children in the age groups 0-4 years, 5-9 years, and 10-14 years were coded to ``Not working" by Stats NZ.
    \end{tablenotes}
\end{threeparttable}
\caption{Population data variables and their values.}
\label{tab:PopData}
\end{table}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\subsubsection{\nmu Sex}\label{ssec:Sx}
Sex is the distinction between males and females based on the biological differences in sexual characteristics.
In responding to a question on sex, most people are able to classify themselves as either male or female. A person who has undergone sex reassignment is classified to that sex. A person who was of indeterminate sex and who has undergone sex assignment is classified to the assigned sex. Someone who is currently undergoing such procedures and living as the sex that they are taking steps towards is classified as that sex.

\subsubsection{\nmu Hours worked in employment} \label{ssec:Hwie}
Hours worked in employment is the total number of hours usually worked in employment each week by a person aged 15 years and over who:
\begin{itemize}
\item worked one hour or more for pay, profit, or payment in kind, in a job, business, farm, or professional practice, or
\item worked one hour or more without pay in work that contributed directly to the operation of a business, farm, or professional practice operated by a relative, or
\item had a job or business they were temporarily absent from.
\end{itemize}

\end{document}

生成此表 由表格代码生成的表格图像

从代码和图像中可以看出,由于测试的长度,我将最后一列的列标题分成两行。我想做的是使用 来\nameref引用我标记的定义。原因是读者单击链接后可以直接转到定义,而不必滚动。这是更长的文档的一部分 - 我的论文 - 因此实际上表格和相关定义之间有几页。

我怎样才能\nameref{ssec:Hwie}替换最后一列的标题,并让文本在两行之间换行?如您所见,我已为“性别”设置了超链接,现在我只需要为“工作时间”设置超链接。

答案1

您可以使用varwidth来设置一个具有最大宽度的框,查看结果后您就可以猜测它的最大宽度。

\documentclass{article}
\usepackage[
  a4paper,
  layout=a4paper,
  bindingoffset=4cm, % <---- really?
  left=0cm,
  right=2cm,
  head=2.5cm,
  bmargin=2cm
]{geometry} 
\usepackage{booktabs}
\usepackage[flushleft]{threeparttable}
\usepackage{varwidth}
\usepackage{hyperref}
\usepackage{cleveref}

\newcommand{\vp}[2]{%
  \begin{varwidth}{#1}\raggedright #2\end{varwidth}%
}

% try and get a lower case first letter for the section hyperlinks working
\newcommand{\lnameref}[1]{%
  \bgroup
  \let\nmu\MakeLowercase
  \nameref{#1}%
  \egroup
}
\newcommand{\fnameref}[1]{%
  \bgroup
  \def\nmu{\let\nmu\MakeLowercase}%
  \nameref{#1}\egroup
}
\newcommand{\nmu}{}

\begin{document}

\begin{table}[htbp]
\centering
\begin{threeparttable}
\begin{tabular}{@{} l l l l l @{}}
\toprule
\nameref{ssec:Sx} &
Age group &
\vp{6em}{\raggedright Partnership status} &
\vp{8em}{\raggedright Usual resident in household\tnote{1}} &
\vp{8em}{\raggedright \nameref{ssec:Hwie}} \\
\midrule 
\addlinespace
Male   & 0--4 years & \nameref{ssec:Prtnrd} & One usual resident & 1--9 hours \\ 
Female & 5--9 years & Non-partnered & Two usual residents & 10--19 hours \\
       & 10--14 years & NEI\tnote{2} & Three usual residents & 20--29 hours \\ 
       & 15--17 years & & Four usual residents & 30--39 hours \\ 
       & 18--24 years & & Five usual residents & 40--49 hours \\
       & 25--34 years & & Six usual residents & 50 hours or more \\ 
       & 35--44 years & & Seven usual residents & Not working\\ 
       & 45--54 years & & Eight or More & NEI\tnote{3} \\ 
       & 55--64 years & & & \\ 
       & 65--74 years & & & \\ 
       & 85 Years \& Over & & & \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\footnotesize
  \item[1] The count of individuals in the household was collected on the 
           separate Dwellings Form, but the information on each individual
           was collected on the Individual Form.
  \item[2] An aggregate of the residual categories. These categories included
           ``response unidentifiable'', ``not stated'', and ``refused to answer''.
           All children in the age groups 0--4 years, 5--9 years, and 10--14 years
           were coded to this personal relationship category by Stats NZ.
  \item[3] An aggregate of the residual categories. These categories included
           ``Don't know'', ``Refused to answer'', ``Response unidentifiable'',
           ``Response outside scope'', and ``Not stated''. Non-response was coded
           to ``Not stated'' unless the respondent clearly indicated they refused
           to answer the question. All children in the age groups 0--4 years,
           5--9 years, and 10--14 years were coded to ``Not working'' by Stats NZ.
\end{tablenotes}
\end{threeparttable}
\caption{Population data variables and their values.}
\label{tab:PopData}
\end{table}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore 
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt 
in culpa qui officia deserunt mollit anim id est laborum.

\subsubsection{\nmu Sex}\label{ssec:Sx}
Sex is the distinction between males and females based on the biological 
differences in sexual characteristics. In responding to a question on sex, 
most people are able to classify themselves as either male or female. 
A person who has undergone sex reassignment is classified to that sex. 
A person who was of indeterminate sex and who has undergone sex assignment 
is classified to the assigned sex. Someone who is currently undergoing such 
procedures and living as the sex that they are taking steps towards is 
classified as that sex.

\subsubsection{\nmu Hours worked in employment} \label{ssec:Hwie}
Hours worked in employment is the total number of hours usually worked in 
employment each week by a person aged 15 years and over who:
\begin{itemize}
\item worked one hour or more for pay, profit, or payment in kind, in a job,
      business, farm, or professional practice, or
\item worked one hour or more without pay in work that contributed directly
      to the operation of a business, farm, or professional practice operated 
      by a relative, or
\item had a job or business they were temporarily absent from.
\end{itemize}

\subsection{Whatever}\label{ssec:Prtnrd}

\end{document}

我只留下了手头代码所需的包。

请注意,数字范围应该使用破折号而不是连字符;我不会在“年龄组”中使用连字符。

"应该''用于结束引号。当然,垂直规则很糟糕。我\centering在里面添加了table\bottomrule

在此处输入图片描述

相关内容