listings,tcolorbox – Solving FontUpper Option Not Working in Tcblisting of Tcolorbox

listingstcolorbox

Please see the following MWE for my queries. Thank you.

MWE:

\documentclass[a4paper]{article}
\usepackage{tcolorbox}
\usepackage{geometry,tcolorbox}
\geometry{showframe}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}
\tcbuselibrary{listings}
\parindent0pt

\begin{document}
Question 1:\\
Why does \verb|fontupper=\huge| not work?\\
How to enlarge the fontsize?

\begin{tcblisting}{fontupper=\huge,listing side text,righthand ratio=0.4,sidebyside gap=4mm,}
\rule{1in}{5pt} some text some text some text some text some text
\end{tcblisting}

Question 2:\\
Why is there an indent on the second line of leftside of the box?\\
And how to eliminate this indent?
\end{document}

enter image description here

Best Answer

It's not really that fontupper=\huge doesn't have any effect. If you were to put fontupper=\huge Hello, then "Hello" would be huge. What's happening is that the style options for the listing are taking over and resetting everything once the listing starts.

You should read the documentation for the listings package; that's what matters here, together with the listing style and listing options for the tcblisting environment which set those options.

By default, with the tcblistings library, you're getting listing style=tcblatex. Apparently that style puts in breaklines=true and a non-zero value for breakindent, which is why you're seeing the indent on the second line.

You could define your own listing style, and use that. Or you could just set the options for the listings package with listing options=. E.g., to make it huge and have no indent:

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{tcolorbox}
\geometry{showframe}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}
\tcbuselibrary{listings}
\parindent0pt

\begin{document}
Question 1:\\
Why does \verb|fontupper=\huge| not work?\\
How to enlarge the fontsize?

\begin{tcblisting}{listing side text,
listing options={breakindent=0pt,breaklines=true,basicstyle=\ttfamily\huge},
righthand ratio=0.4,sidebyside gap=4mm}
\rule{1in}{5pt} some text some text some text some text some text
\end{tcblisting}

Question 2:\\
Why is there an indent on the second line of leftside of the box?\\
And how to eliminate this indent?
\end{document}

Not exactly pretty, but you get the idea.

tcblisting output