3

I know there has been questions similar to this previously but none of the proposed solutions seem to work for me.

I have a few custom environments I am using in LaTeX. Below is the code for a "licenses" environment. This environment is basically a table and I use the "license" command to specify each row of the table.

\newenvironment{licenses}
{%
\def\lwidth{0.25\textwidth}%
\def\rwidth{0.69\textwidth}%
%
\newcommand\license[3]{%
\ifdef{\separator}{\separator}{}%
##1 & ##3 %
\def\separator{\\}%
}%
%
\begin{longtable}{>{\bfseries}L{\lwidth}!{\VRule}R{\rwidth}}%
}
{\end{longtable}}

I then use the environment as follows... however I have a problem in that the whitespace between each \license command affect the output.

\begin{licenses}
\license{...}{...}

\license{...}{...}

\license{...}{...}

\end{licenses}

I have tried the \ignorespaces command and also commands similar to \catcode32=9\relax, but none of these seem to work in my case.

Here is a minimum working example:

\documentclass[10pt]{article}

\usepackage{etoolbox}           % for ifdef
\usepackage{longtable}          % for tables that span more than one page
\usepackage{tabularx}           % for newcolumntype
\usepackage{xcolor}             % for colours

\definecolor{lightgray}{gray}{0.8}
\newcolumntype{L}[1]{>{\raggedleft}p{#1}}
\newcolumntype{R}[1]{p{#1}}
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}

\newenvironment{licenses}
 {%
\def\lwidth{0.25\textwidth}%
\def\rwidth{0.69\textwidth}%
%
\newcommand\license[3]{%
\ifdef{\separator}{\separator}{}%
##1 & ##3 %
\def\separator{\\}%
}%
%
\begin{longtable}{>{\bfseries}L{\lwidth}!{\VRule}R{\rwidth}}
}
{\end{longtable}}

\begin{document}
\section*{Licenses}
\begin{licenses}
\license{Test1}{Test1}{Test1}

\license{Test2}{Test2}{Test2}

\license{Test3}{Test3}{Test3}

\end{licenses}
\end{document}
7
  • Note that it is not "whitespace" but empty lines, which are converted to \par by tex. You can try redefining locally \par.
    – JLDiaz
    Jul 9, 2012 at 22:22
  • 1
    While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Jul 9, 2012 at 22:23
  • Your code fragments don't seem to match: you define \licence to have three arguments (but it doesn't use #2 ? but your use of \license only shows two arguments. Please post a complete document that shows the problem. Jul 9, 2012 at 23:41
  • @PeterGrill - Sorry about that. Have included a MWE. Jul 9, 2012 at 23:43
  • 1
    Why are you defining \license in that way? A simple \newcommand{\license}[3]{#1&#2\\} outside the definition of licenses (or even inside it, with double ##) will do, avoiding the blank lines.
    – egreg
    Jul 9, 2012 at 23:49

2 Answers 2

1

Recently, I have been looking for a Command that gobbles all following empty lines. The main idea is to define a command \gobblepars (taken from this blog):

\makeatletter
\newcommand\gobblepars{%
    \@ifnextchar\par%
        {\expandafter\gobblepars\@gobble}%
        {}}
\makeatother

Does it work if you use this command as the very last command of the definition of your \license command?

2
1

Assuming that nothing goes in the licenses environment, a refinement of user946850's idea can work:

\documentclass[10pt]{article}

\usepackage{longtable}          % for tables that span more than one page
\usepackage{xcolor}             % for colours

\definecolor{lightgray}{gray}{0.8}
\newcolumntype{L}[1]{>{\raggedleft}p{#1}}
\newcolumntype{R}[1]{p{#1}}
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}

\newcommand{\license}[3]{%
  #1 & #3 \bingo
}
\makeatletter
\newcommand\bingo{%
  \@ifnextchar\par
    {\expandafter\bingo\@gobble}
    {\@ifnextchar\end{}{\\[2ex]}}}
\makeatother
\newenvironment{licenses}
 {%
  \def\lwidth{0.25\textwidth}%
  \def\rwidth{0.69\textwidth}%
  \begin{longtable}{>{\bfseries}L{\lwidth}!{\VRule}R{\rwidth}}
}
{\end{longtable}}
\usepackage{lipsum}
\begin{document}
\section*{Licenses}
\begin{licenses}

\license{Test1}{Test1}{Test1}

\license{Test2}{Test2}{Test2}

\license{Test3}{Test3}{Test3}

\end{licenses}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .