1

I'm attempting to define a custom tabbing environment which allows me to align subsequent lines of text with elements in a previously generated block which cannot be inside the tabbing environment. So far this is what I've got:

\documentclass{article}

\usepackage[savepos]{zref}

\newenvironment{nstabbing}
  {\setlength{\topsep}{0pt}%
   \setlength{\partopsep}{0pt}%
   \tabbing}
  {\endtabbing\setcounter{tabstop}{0}}

\newcounter{tabstop}
\newcommand{\align}{%
    \stepcounter{tabstop}%
    \expandafter\zsavepos{stop\thetabstop}%
}

\begin{document}
First{\align} I have{\align} something{\align} which sets{\align} the alignment {\align}points.
\begin{nstabbing}
\hspace*{-\oddsidemargin}\hspace{-1in}\hspace{\zposx{stop1} sp}\=%
\hspace{-\zposx{stop1} sp}\hspace{\zposx{stop2} sp}\=%
\hspace{-\zposx{stop2} sp}\hspace{\zposx{stop3} sp}\=%
\hspace{-\zposx{stop3} sp}\hspace{\zposx{stop4} sp}\=%
\hspace{-\zposx{stop4} sp}\hspace{\zposx{stop5} sp}\=%
\kill
\>Some\>thing\>using\>those\>alignment points.\\
\end{nstabbing}

\end{document}

Note: For the purposes of this MWE I've substituted simple text for the block which generates the alignment points in order to minimize the number of packages needed for the MWE. Moving this block inside the tabbing environment is not possible in the actual use case.

This works, but constructing the kill line manually is overly complicated, especially when the number of tab stops increases (I might have up to 20 or so in some use cases). What I'd like to do is automate that so that it can be part of the custom environment definition.

The way I figure, I know how many tab stops need to be defined and what their names are when the environment starts based on the current value of the counter tabstop. What I need to do then, is loop over the locations in some fashion to define each one. Does anyone have any suggestions for how I might modify the definition of nstabbing so that it does this automatically?

1

Here's a different definition of \align (and I suggest a different name, because \align is taken by amsmath) and also a \setstops macro that you can possibly add to the definition of nstabbing, if you prefer.

\documentclass{article}

\usepackage[savepos]{zref}

\newenvironment{nstabbing}
  {\setlength{\topsep}{0pt}%
   \setlength{\partopsep}{0pt}%
   \tabbing}
  {\endtabbing\setcounter{tabstop}{0}}

\newcounter{tabstop}
\makeatletter
\newcommand{\AL}{%
  \@bsphack
  \stepcounter{tabstop}%
  \expandafter\zsavepos{stop\thetabstop}%
  \@esphack
}

\newcommand{\setstops}{%
  \gdef\nstabbing@stops{%
    \hspace*{-\oddsidemargin}\hspace{-1in}%
    \hspace{\zposx{stop1} sp}\=%
  }%
  \count@=\@ne
  \loop\ifnum\count@<\value{tabstop}%
    \begingroup\edef\x{\endgroup
      \noexpand\g@addto@macro\noexpand\nstabbing@stops{%
        \noexpand\hspace{-\noexpand\zposx{stop\the\count@} sp}%
        \noexpand\hspace{\noexpand\zposx{stop\the\numexpr\count@+1} sp}\noexpand\=%
      }%
    }\x
    \advance\count@\@ne
  \repeat
  \nstabbing@stops\kill
}
\makeatother

\begin{document}
First \AL I have \AL something \AL which sets \AL the alignment  \AL points.
\begin{nstabbing}\setstops
\>Some\>thing\>using\>those\>alignment points.\\
\end{nstabbing}

\end{document}

enter image description here

  • Thank you much. I ended up having to add another counter to the stop name to make this reusable in the same document, but this works great. – rpspringuel Feb 27 '16 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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