fancyvrb
Advantages
- Absolute real verbatim.
- Saves the typing of
\verb
.
Disadvantages
Code
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs,longtable,fancyvrb}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\ifPreview \let\longtable\tabular \let\endlongtable\endtabular \fi
\PreviewEnvironment{longtable}
\DefineShortVerb{\|}
\begin{document}
\begin{longtable}{lls}
\toprule
Unit & Macro & Symbol \\ \midrule
ampere & |\ampere| & \ampere \\
candela & |\candela| & \candela \\
kelvin & |\kelvin| & \kelvin \\
kilogram & |\kilogram| & \kilogram \\
meter & |\meter| & \meter \\
mole & |\mole| & \mole \\
second & |\second| & \second \\ \bottomrule
\end{longtable}
\end{document}
Output
(See next output.)
collcell
& \string
(+ s
column)
Advantages
- You can write
\<macro>
without a problem.
- Does not need
T1
/lmodern
(but that would not hurt either).
- You can hide the first line with
\multicolumn
.
Disadvantages
Code
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs,longtable,collcell}
\newcommand*{\myString}[1]{\texttt{\string#1}}
\newcolumntype{v}{>{\collectcell\myString}l<{\endcollectcell}}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\ifPreview \let\longtable\tabular \let\endlongtable\endtabular \fi
\PreviewEnvironment{longtable}
\begin{document}
\begin{longtable}{lvs}
\toprule
Unit & \multicolumn{1}{l}{Macro} & Symbol \\ \midrule
ampere & \ampere & \ampere \\
candela & \candela & \candela \\
kelvin & \kelvin & \kelvin \\
kilogram & \kilogram & \kilogram \\
meter & \meter & \meter \\
mole & \mole & \mole \\
second & \second & \second \\ \bottomrule
\end{longtable}
\end{document}
Output

\detokenize
Advantage
- You can write
\<macro>
without a problem.
- Nearly full verbatim
- More than one macro allowed
\\
, %
and &
are not allowed, braces must match
Disadvantages
- The first line gets de-tokenized.
- You cannot use any macros in the first line.
Code
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs,longtable,collcell}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\newcounter{rowcounter}
\newcolumntype{v}{>{\ifnum\value{rowcounter}>0\relax\ttfamily\fi\collectcell\detokenize}l<{\endcollectcell\stepcounter{rowcounter}}}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\ifPreview \let\longtable\tabular \let\endlongtable\endtabular \fi
\PreviewEnvironment{longtable}
\expandafter\def\expandafter\tabular\expandafter{\tabular\setcounter{rowcounter}{0}}
\begin{document}
\begin{longtable}{lvl}
\toprule
Unit & Macro & Symbol \\ \midrule
ampere & \ampere & \si{\ampere} \\
candela & \candela & \si{\candela} \\
kelvin & \kelvin & \si{\kelvin} \\
kilogram & \kilogram & \si{\kilogram} \\
meter & \meter & \si{\meter} \\
mole & \mole & \si{\mole} \\
second & \second & \si{\second} \\ \bottomrule
\end{longtable}
\end{document}
Output

\DefineShortVerb
from thefancyvrb
package (saves typing). Solution 2: Use an editor that 2a) aligns tabular material at the&
and 2b) provides block editing. Solution 3. Combine David Carlisle’s answer with thecollcell
package. – Qrrbrbirlbel Jan 6 '13 at 2:52longtable
stuff the content is simply that\csname#1\endcsname
turns a name into a macro, and\expandafter\string\csname#1\endcsname
turns it into a textual representation of the control sequence. With\csname
and\string
being defined precisely for these purposes, that's as simple as it gets. Note that you don't really need\verb
to format the macro, since its two functions, to prevent expansion and change the font, are separately taken care of by\string
and\texttt
. – Ryan Reich Jan 6 '13 at 3:01