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}
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

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

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.