Text FormattingFont Size in Listings

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
colino
Posts: 4
Joined: Tue May 21, 2013 12:59 pm

Font Size in Listings

Post by colino »

Hi,

I'm new to LaTeX. I need to have text size as 11pt in a listing (and only in the listings environment). My settings are these:

Code: Select all

\lstset{numbers=left,
  inputencoding=latin1,
  basicstyle=\footnotesize\ttfamily,
  keywordstyle=\color{blue},         
  breaklines=true, 
  showtabs=false,
  showstringspaces=false,
  numberstyle=\tiny\color{mygray}
}  
How I can do this? And how can I solve bad encoding of "è" character?

Recommended reading 2024:

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

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

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Font Size in Listings

Post by cgnieder »

colino wrote:I need to have text size as 11pt in a listing (and only in the listings environment).
I do not understand what you mean. Do you mean you want a fixed 11pt size for your listings regardless of the font size of your document?
colino wrote:And how can I solve bad encoding of "è" character?
What bad encoding? Can you please make a Infominimal working example that demonstrates it?

Regards
site moderator & package author
colino
Posts: 4
Joined: Tue May 21, 2013 12:59 pm

Font Size in Listings

Post by colino »

colino wrote:I do not understand what you mean. Do you mean you want a fixed 11pt size for your listings regardless of the font size of your document?
Yes. Sorry for my English :D
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Font Size in Listings

Post by cgnieder »

Here's one way:

Code: Select all

\documentclass[10pt]{article}
\usepackage{listings}

\lstset{
  basicstyle=\fontsize{11}{13}\selectfont\ttfamily
}

\begin{document}

Text before
\begin{lstlisting}
  foo bar baz
  (/$%$
\end{lstlisting}
Text after

\end{document}
Regards
site moderator & package author
colino
Posts: 4
Joined: Tue May 21, 2013 12:59 pm

Re: Font Size in Listings

Post by colino »

many thanks!
Post Reply