1

I have two command I have created with \newcommand, both work find. One is \mydate{date_variable} the other is \PrintOne{Variable1}{Variable2}. My problem is I can not figure out how I can put them in two of my columns in a tabularx table.

The TeX report is begin called from a program that is not mine so I do not have any way of changing it. I do know the data being passed to it, and can print everything I need, just not in a tabularx :(

  • 1
    Your question is unclear. You should show an example of the tabular and where the commands should appear/do something. A tip: You can use backticks ``` to mark your inline code as I did in my edit. –  Jun 05 '15 at 14:49
  • This question seems to be a follow-up of http://tex.stackexchange.com/questions/248403/here-is-a-short-bit-of-latex-code-that-keeps-crashing-why/248407#248407 –  Jun 05 '15 at 14:50
  • \begin{tabularx}{19cm}{C{5mm} L{1.5cm} L{4.5cm} L{5cm} C{1cm} C{1cm} R{1.25cm} R{1.25cm} } \textbf{#} & \textbf{Number} & \textbf{Description} & \textbf{Notes} & \textbf{Qt'y} & \textbf{Unit} & \textbf{Price} & \textbf{Amount} \\ [0.5em]<%foreach number%> <%runningnumber%> & <%number%> & <%description%> & <%itemnotes%> & <%qty%> & <%unit%> & <%sellprice%> & <%linetotal%> \ <%end number%>\end{tabularx} ` Think this is what you were looking for. As before, yes I need to be able to print %description% only if %itemnotes% is blank, otherwise print %itemnotes%. – Gregory West Jun 06 '15 at 19:08
  • Column widths are not an issue as they are static. Again, I do not have any control over the calling program. I am trying to fix a report that is being printed. – Gregory West Jun 06 '15 at 19:09

1 Answers1

2

The body of tabularx is executed multiple times, to find the best column widths, so \newcommand doesn't work as it generates an error on the second trial.

Use \newcommand\mycommand{} before the table to initialise then you can use \renewcommand\mycommand{..} within the tabularx.

David Carlisle
  • 757,742
  • Or the non-LaTeX way of using \def, for me it's like the local version of \newcommand (altough I know \newcommand is not \global). – Manuel Jun 05 '15 at 17:04
  • @Manuel if you do that you are not warned if you over-write a command \def\count{...} would be bad for example. Doing it as above you would get an error for that. – David Carlisle Jun 05 '15 at 17:44
  • Yes, I know. I wrote the comment to say what's the most common way of dealing with that, of course, at your own risk. – Manuel Jun 05 '15 at 17:48
  • I tried putting {\ifblank{<%itemnotes%>}{<%description%>}{<%itemnotes%>}} But what is happening is I am getting Itemnotes, printed twice, with description in the middle... ARGH – Gregory West Jun 22 '15 at 15:38
  • @GregoryWest it is impossible to guess from fragments in comments what you did. Please edit the question to have a complete small document from \documentclass to \end{document} that reproduces the error. Add it to the question and mark as a code block using {} in the editor. – David Carlisle Jun 22 '15 at 15:45
  • %% MAIN DETAIL LINE \begin{tabularx}{19cm}{C{5mm} L{2.1cm} L{8.5cm} C{1cm} C{7mm} R{1.5cm} R{1.5cm} } %%\begin{tabularx}{19cm}{p{5mm} l l l c c r r c c c} \textbf{#} & \textbf{Number} & \textbf{Description / Notes} & \textbf{Qt'y} & \textbf{Unit} & \textbf{Price} & \textbf{Amount} \ [0.5em] <%foreach number%> <%runningnumber%> & <%number%> & {\ifblank{<%itemnotes%>}{<%description%>}{<%itemnotes%>}} & <%qty%> & <%unit%> & <%sellprice%> & <%linetotal%> \ \ <%end number%> \end{tabularx}

    Here is the section in question. the whole document is rather long to post here.

    – Gregory West Jun 22 '15 at 16:10
  • @GregoryWest no sorry as I said it is impossible to tell what you did from fragments in comments. – David Carlisle Jun 22 '15 at 16:12
  • @GregoryWest in particular I can't even guess what you mean by <%foreach number%> which doesn't appear to be tex at all. – David Carlisle Jun 22 '15 at 16:30
  • Understood. This is a report from a web based program. The Tex is being passed a bunch of arrays of line information. The %for each% causes each line item to be printer out on the report. There are two fields, %itemnotes% and %description%. Basically I need Description printer out, UNLESS there is something in %itemnotes% then it supersedes %description%. I would have thought this would be a straight forward thing to do, obviously I was mistaken... – Gregory West Jun 22 '15 at 17:03
  • @GregoryWest The report generator is completely off topic. You can add to your question a sample generated report that is a complete tex document, and ask about that. – David Carlisle Jun 22 '15 at 17:44