2

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}
belitd
  • 345

1 Answers1

2

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).

enter image description here

egreg
  • 1,121,712