Text Formatting ⇒ problem with verbatim layout
problem with verbatim layout
I am using
\begin{verbatim}
to embedd some code into my document - however the formatting gets lost, I would like to retain the spaces and indentation of the text - I am aware of the * option to show whitepsaces but this is not what I want. Is there a way to display the code with the same formatting as i.e. in Visual Studio without having to add the spaces by hand inside Latex? When I copy/paste the Visual Studio code into the document it is displayed correctly, however when rendered everything is right-aligned.
Any tricks? Thanks.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
problem with verbatim layout
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: problem with verbatim layout
I just want to use one line code that doesn't worth using listing but since it's long, it goes beyond the page margin. How is it possible to display the one-line code in page layout using \begin{verbatim} ... or \verb+....+
Thanks
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
problem with verbatim layout
You have to set the line break feature explicitly.carol wrote:I also used listing package and according to the user's guide, it has an automatic feature of breaking long codes but it doesn't.[…]
Code: Select all
\lstset{%
breaklines=true
}Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10