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.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- 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