makeatletter 命令中的换行符

makeatletter 命令中的换行符

由于某种原因,我在表格单元格中使用命令时会出现换行符\textlabel。其他命令似乎都运行正常。

\documentclass[a4paper]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}
\usepackage[pdftex,bookmarks=true,bookmarksnumbered,colorlinks=true]{hyperref} % http://ctan.org/pkg/hyperref
\usepackage{nameref}

\begin{document}

\makeatletter
    \newcommand*{\textlabel}[2]{%
        \edef\@currentlabel{#1}% Set target label
        \phantomsection% Correct hyper reference link
        #1\label{#2}% Print and store label
    }  
\makeatother

\section{Section}
\paragraph*{\textlabel{Paragraph}{paragraph}}
\paragraph*{}
\begin{tabular}{lp{10cm}}
    \hline
    \textbf{Col 1} & \textbf{Col 2} \\ \hline
    Bla1 & \textlabel{Blubb1}{reference1} \\
    & Description1 \\ 
    Bla2 & \textlabel{Blubb2}{reference2} \\
    & Description2 \\ \hline
\end{tabular}
\end{document}

答案1

避免在垂直模式下执行操作,尤其是在表格单元格的开始处。

\makeatletter
    \newcommand*{\textlabel}[2]{%
        \edef\@currentlabel{#1}% Set target label
        \leavevmode\phantomsection% Correct hyper reference link
         %%%%%%%%%%
        #1\label{#2}% Print and store label
    }  
\makeatother

相关内容