我创建了一个新命令,其功能按预期工作,但输出有点出乎意料。如您所见,“Else”文本与“Kaldenavn”文本不对齐。这是怎么回事?我该如何修复?
我创建的方法是:textlabel
最低工作代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{tabularx} % Til tabeller der tilpaser sig i bredden
\newcolumntype{R}{>{\raggedleft\arraybackslash}r}
\usepackage{xifthen} % Used to test if an argument is empty
\usepackage{datetime} % Used to format dates
\newdateformat{timeLineDate}{\THEDAY.~\shortmonthname~\THEYEAR}
\newdateformat{monthYearDate}{\monthname[\THEMONTH]~\THEYEAR}
\makeatletter
\newcommand*{\textlabel}[2]{%
\edef\@currentlabel{#1}% Set target label
\phantomsection% Correct hyper reference link
#1\label{#2}% Print and store label
}
\makeatother
%Arguments:
% 1) MANDATORY - Reference to the current full name
% 2) MANDATORY - Full birth name
% 3) OPTIONAL - Called name
% 4) OPTIONAL - Birth date in the format of dd. mmm. yyyy
% 5) OPTIONAL - Death date in the format of dd. mmm. yyyy
% 6) MANDATORY - Uniqueue Reference number
\newcommand{\createPerson}[6]
{
\begin{tabularx}{\textwidth}{lXRc}%
Navn: & \nameref{#1} & \ifNoArgumentElse{#4}{&}{#4 & $\star$}\\%
\ifNoArgumentElse{#2}{Kaldenavn: & \textlabel{#3}{sth:text}}{Fødenavn: & #2} & \ifNoArgumentElse{#5}{&}{#5 & \cross}%
\ifNoArgumentElse{#2}{\\&& #6 & $\Re$}{\\Kaldenavn: & \textlabel{#3}{abc:#3} & #6 & $\Re$}%
\end{tabularx}%
}
%Arguments
% 1) The argument to test
% 2) If empty then do this
% 3) If not empty then do this
\newcommand{\ifNoArgumentElse}[3]{
\ifthenelse{\isempty{#1}}{#2}{#3}%
}
\newcommand{\cross}[1][1pt]{\ooalign{%
\rule[1ex]{1ex}{#1}\cr% Horizontal bar
\hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}
\begin{document}
\subsection{Else Jensen}
\label{person1}
\createPerson
{person1}
{Else Nielsen}
{Else}
{11. sep. 2010}
{13. nov. 2013}
{222}
\ref{abc:Else} was a good student.
\end{document}