Text FormattingMake verbatim font like text outside verbatim or wrap text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Michael_590
Posts: 51
Joined: Wed Aug 06, 2014 6:59 pm

Make verbatim font like text outside verbatim or wrap text

Post by Michael_590 »

How can I get the text inside the verbatim command to exactly match the text outside of the verbatim command.

Code: Select all

\documentclass{article}
    \usepackage{caption}
    \usepackage{graphicx}
    \begin{document}
    \listoffigures
    \bigbreak
Hello, how are you?
\begingroup
    \fontsize{9pt}{9pt}\selectfont
    \begin{verbatim}  
    Hello, how are you? 9pt
    \end{verbatim}  
\endgroup
    \end{document}
Thank you,
Last edited by Michael_590 on Fri Aug 22, 2014 8:32 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Make verbatim font like text outside verbatim or wrap text

Post by Johannes_B »

I am not quite sure what you mean. Verbatim switches to a non-proportional typrewriter font. You can change that, of course, but there is a reason for that.

You might also be interested in package listings.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Michael_590
Posts: 51
Joined: Wed Aug 06, 2014 6:59 pm

Re: Reliable way to make verbatim font like text outside

Post by Michael_590 »

I think I'm having problems with too much text inside the verbatim. So, I was thinking of moving part of the text outside the verbatim. And, have the text outside and inside be the same font, same size, etc.

Basically, I have a few long sentances in front of a few columns of data. I'd want to try and put the sentances outside of the verbatim, and put the columns inside the verbatim.

I already looked at the listing package, but I didn't see anything that I had to have.

Thank you,
Michael_590
Posts: 51
Joined: Wed Aug 06, 2014 6:59 pm

Make verbatim font like text outside verbatim or wrap text

Post by Michael_590 »

Thanks,

I'm going to try to use:

Code: Select all

\documentclass{article}
\usepackage{listings}
\lstset{
   breaklines=true,
   basicstyle=\ttfamily}
\begin{document}

\begin{verbatim}
This is a very very very very very very long line that will run off the page in verbatim but not in lstlisting with breaklines=true.
\end{verbatim}

\begin{lstlisting}
This is a very very very very very very long line that will run off the page in verbatim but not in lstlisting with breaklines=true.
\end{lstlisting}

\end{document}
But, when I incorporate the above into my own large document I get the error:

!Latex Error: File 'lstlisting.sty' not found.

I get this error when I use the pdflatex command.

Thank you,
Michael_590
Posts: 51
Joined: Wed Aug 06, 2014 6:59 pm

Re: Reliable way to make verbatim font like text outside

Post by Michael_590 »

Thank you, it's working.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Reliable way to make verbatim font like text outside

Post by Johannes_B »

Michael, you need to work on the details. The package is called listings, not lstlistings. Again, you could have clicked »Open in writelatex«.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Michael_590
Posts: 51
Joined: Wed Aug 06, 2014 6:59 pm

Make verbatim font like text outside verbatim or wrap text

Post by Michael_590 »

Well, I'm no longer getting the Error that I talked about above, but the text is no wrapping around as desired.

Can I put the below two "lstset" option setting in the "\usepackage{listings}" command. If I can put the "breaklines" and "basicstyle" options in the "\usepackage" can you post the code showing how to do that.

Code: Select all

\documentclass{article}
\usepackage{listings}
\lstset{
   breaklines=true,
   basicstyle=\ttfamily}
\begin{document}

\begin{verbatim}
This is a very very very very very very long line that will run off the page in verbatim but not in lstlisting with breaklines=true.
\end{verbatim}

\begin{lstlisting}
This is a very very very very very very long line that will run off the page in verbatim but not in lstlisting with breaklines=true.
\end{lstlisting}

\end{document}
Thank you,
Post Reply