LaTeX's \label
-\ref
system by default works along the following lines:
- With the issue of
\label{<lab>}
, LaTeX stores the last updated counter that used \refstepcounter
and the associated page number in the .aux
file. \label
actually uses \@currentlabel
, which is set by \refstepcounter
. This step only occurs at page shipout to ensure that the correct page number is associated with the label;
- An issue of
\ref
retrieves the counter written during \label
(\@currentlabel
) while \pageref
retrieves the accompanying page number.
listings
has a counter for each lstlisting
(the counter lstlisting
), but also a counter for each line of a specific listing (the counter lst@lineno
).
If you wish to reference the counter for the listing, place your \label
immediately after the listing \caption
. If you wish to reference the counter for a line within the listing, place your \label
on the appropriate line.
Starting with tcolorbox version 2.71 (2014/02/21)
, all missing comment outside listing
e.a. options are implemented. A comment is considered as quite anything, especially a picture. For pictures, there is the new option image comment
which simply sets a picture as comment.
A comment outside a tcolorbox
(left/right/below/above) is always considered as the lower part of the box content. Thus, in the following example, center lower
is centering a picture which is actually above the listing.
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcblisting{mylisting}[1]{%
colback=red!5!white,colframe=red!75!black,
image comment={width=2.5cm}{example-image-a.pdf},
#1}
\begin{document}
\section{listing outside image}
\begin{mylisting}{listing outside comment,righthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\section{image outside listing}
\begin{mylisting}{comment outside listing,lefthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\section{listing above image}
\begin{mylisting}{listing above comment,center lower}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\section{image above listing}
\begin{mylisting}{comment above listing,center lower}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\clearpage
\section{listing side image}
\begin{mylisting}{listing side comment,lower separated=false,
righthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\section{image side listing}
\begin{mylisting}{comment side listing,lower separated=false,
lefthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\section{listing and image}
\begin{mylisting}{listing and comment,bicolor,colbacklower=white,center lower}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\section{image and listing}
\begin{mylisting}{comment and listing,bicolor,colback=white,
colbacklower=red!5!white,center upper}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}
\end{document}
Best Answer
You cannot use two source listings within a
tcblisting
, but you can put two listings side by side into atcolorbox
: