1

I have written a macro that uses the functions in 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-}}{} }

What this does is change a date from 2015-10-07 to 2015-Oct-07. It works great, sort of. Now when I print it in a 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}

I get a blank line before and after the line of data. If I take out \yyyymmmdd and just print <%invdate%> I do not get the blank lines. What would cause this?

closed as unclear what you're asking by Zarko, Stefan Pinnow, gernot, user31729, Mensch Feb 11 '17 at 14:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    You're probably using something else to insert the "correct date" instead of <%invdate%>, as (La)TeX considers % to represent a comment character. My guess is you have spurious spaces in your macro, causing the problem. See What is the use of percent signs (%) at the end of lines?. – Werner Oct 7 '15 at 18:31
  • Please tell us how the L and C column types a defined. (Are they just raggedright and centered versions of X If so, why do they have explicit widths?) Please also provide at least two valid non-header rows of input for the tabularx environment, so that we can test what's going on. – Mico Oct 7 '15 at 18:45
  • 1
    there is no possible way tabularx can do anything useful with this table, all the column widths are specified in advance, and the cells are (I would guess) small items not involving linebreaking. tabularx is all about adjusting the widths for linebreaking with a column. – David Carlisle Oct 7 '15 at 18:56
1

With a simpler solution for the date macro. However, I do not know how you get the data. The reason why I used only text:

\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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.