# Preserve spacing in \verb

I'm writing a document in which I want to insert some Python code. I wanted to display it in a tabular so I used the

\verb


tag, it is working pretty well, but it just removes the leading spaces for each instruction, which is problematic as I show Python code ...

Here is a MWE :

\documentclass{article}
\usepackage[left=4cm,right=4cm,top=2cm,bottom=2cm]{geometry} % Marges

%%% For french
\usepackage[utf8]{inputenc}
\usepackage[cyr]{aeguill}
\usepackage{xspace}
\usepackage[francais]{babel}

\usepackage{fancyvrb}

\begin{document}
\begin{tabular}{l l}
\hline
Boucle & Code \\
\hline \\[-0.2cm]
while &
\verb|while (condition d'arrêt non vérifiée): | \\
& \verb|    instructions | \\
& \verb|else: | \\
& \verb|    instructions exécutées lorsque le while est terminé|\\
\end{tabular}

\end{document}

• My leading verbatim spaces are not removed when I compile your document Oct 25 '17 at 15:29
• Ugh, on Texmaker I just have 1 space instead of the tab I would like Oct 25 '17 at 15:32
• Nevermind, solved it by replacing \verb by \Verb ... Oct 25 '17 at 15:37
• If the issue is tab vs. space, there are questions on that around here: tex.stackexchange.com/questions/389030/… and tex.stackexchange.com/questions/41951/… Oct 25 '17 at 15:41

You can do it much more easily:

\documentclass{article}
\usepackage[left=4cm,right=4cm,top=2cm,bottom=2cm]{geometry} % Marges

%%% Pour le français
\usepackage[T1]{fontenc}% <--- IMPORTANT
\usepackage[utf8]{inputenc}
%\usepackage[cyr]{aeguill}% <--- OBSOLETE
\usepackage[french]{babel}% <--- francais is deprecated

\usepackage{fancyvrb}
\usepackage{booktabs}% <--- better rules

\begin{document}
\begin{tabular}{l l}
\toprule
Boucle & Code \\
\midrule
while &
\begin{BVerbatim}[fontsize=\normalsize,baseline=t]
while (condition d'arrêt non vérifiée):
instructions
else:
instructions exécutées lorsque le while est terminé
\end{BVerbatim}
\end{tabular}

\end{document}


Note that aeguill is obsolete and the francais option is deprecated (use french).

• Wow, thank you very much for all your comments ! Oct 25 '17 at 15:44