Hi,
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.
Text Formatting ⇒ problem with verbatim layout
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
problem with verbatim layout
Use the listings package to format the code. Usable solutions can be found by using the search function of the forum.
Best regards
Thorsten
Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: problem with verbatim layout
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.
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
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
}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10