我编写了一个使用以下函数的宏xstring
:
\newcommand{\yyyymmmdd}[1]
{\IfSubStr{#1}{-01-}{\StrSubstitute{#1}{-01-}{-Jan-}}{}
\IfSubStr{#1}{-02-}{\StrSubstitute{#1}{-02-}{-Feb-}}{}
\IfSubStr{#1}{-03-}{\StrSubstitute{#1}{-03-}{-Mar-}}{}
\IfSubStr{#1}{-04-}{\StrSubstitute{#1}{-04-}{-Apr-}}{}
\IfSubStr{#1}{-05-}{\StrSubstitute{#1}{-05-}{-May-}}{}
\IfSubStr{#1}{-06-}{\StrSubstitute{#1}{-06-}{-Jun-}}{}
\IfSubStr{#1}{-07-}{\StrSubstitute{#1}{-07-}{-Jul-}}{}
\IfSubStr{#1}{-08-}{\StrSubstitute{#1}{-08-}{-Aug-}}{}
\IfSubStr{#1}{-09-}{\StrSubstitute{#1}{-09-}{-Sep-}}{}
\IfSubStr{#1}{-10-}{\StrSubstitute{#1}{-10-}{-Oct-}}{}
\IfSubStr{#1}{-11-}{\StrSubstitute{#1}{-11-}{-Nov-}}{}
\IfSubStr{#1}{-12-}{\StrSubstitute{#1}{-12-}{-Dec-}}{} }
这样做的目的是将日期从 2015-10-07 更改为 2015-Oct-07。效果不错。现在当我将其打印出来时tabularx
:
\begin{tabularx}{19cm}{p{1.75cm}C{1.85cm}C{2cm}L{2.5cm}L{4cm}L{4cm}} \hline
\textbf{Invoice \#} & \textbf{Date} & \textbf{Customer \#} & \textbf{P.O. \#}
& \textbf{Description} & \textbf{Salesperson} \\ [0.5em]
<%invnumber%> & \yyyymmmdd{<%invdate%>} & <%customernumber%> & <%ponumber%>
& <%shippingpoint%> & <%employee%> \\
\hline
\end{tabularx}
我在数据行前后都看到空白行。如果我取出\yyyymmmdd
并直接打印,<%invdate%>
则不会看到空白行。这是什么原因造成的?
答案1
为日期宏提供了一个更简单的解决方案。但是,我不知道您如何获取数据。我只使用文本的原因是:
\documentclass{article}
\usepackage{tabularx}
\newcolumntype{L}[1]{p{#1}}% dummy
\newcolumntype{C}[1]{p{#1}}% dummy
\newcommand\yyyymmmdd[1]{\YYYYMMDD#1}
\def\YYYYMMDD#1-#2-#3{#1-%
\ifcase#2
\or Jan\or Feb\or Mar\or Apr\or May\or Jun\or Jul%
\or Aug\or Sep\or Oct\or Nov\or Dec\fi
-#3}
\begin{document}
\begin{tabularx}{19cm}{p{1.75cm}C{1.85cm}C{2cm}L{2.5cm}L{4cm}L{4cm}} \hline
\textbf{Invoice \#} & \textbf{Date} & \textbf{Customer \#} & \textbf{P.O. \#}
& \textbf{Description} & \textbf{Salesperson} \\ [0.5em]
foo & \yyyymmmdd{2015-07-07} & foo & bar
& foobar & foobaz \\
\hline
\end{tabularx}
\end{document}