Skip to content

Commit

Permalink
Fix the caption of marginlisting
Browse files Browse the repository at this point in the history
  • Loading branch information
pi8027 committed Sep 27, 2022
1 parent 81bfb18 commit 873ef2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
9 changes: 2 additions & 7 deletions examples/documentation/chapters/textnotes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,21 @@ \section{Marginlisting}
limited, especially for the captions, but you can try the following
code:

\begin{marginlisting}[-1.35cm]
\begin{marginlisting}
\caption{An example of a margin listing.}
\vspace{0.6cm}
\begin{lstlisting}[language=Python,style=kaolstplain]
print("Hello World!")
\end{lstlisting}
\end{marginlisting}

\begin{verbatim}
\begin{marginlisting}[-0.5cm]
\begin{marginlisting}
\caption{My caption}
\vspace{0.2cm}
\begin{lstlisting}[language=Python,style=kaolstplain]
... code ...
\end{lstlisting}
\end{marginlisting}
\end{verbatim}

Unfortunately, the space between the caption and the listing must be
adjusted manually; if you find a better way, please let me know.

Not only textual stuff can be displayed in the margin, but also figures.
Those will be the focus of the next chapter.
28 changes: 13 additions & 15 deletions kao.sty
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
\marginskip{\kaomarginskipabove}%
\begin{lrbox}{\@sidenotes@marginlistingbox}%
\begin{minipage}{\marginparwidth}%
\captionsetup{type=lstlisting}%
\captionsetup{type=lstlisting, format=margin}%
}{%
\end{minipage}%
\end{lrbox}%
Expand Down Expand Up @@ -678,14 +678,15 @@
\DeclareCaptionFormat{llap}{%
\begin{lrbox}{\mycap}%
\begin{minipage}{\marginparwidth}%
\@margin@par #1:#2#3%
\@margin@par #1#2#3%
\end{minipage}%
\end{lrbox}%
\marginnote[0.2cm]{\usebox\mycap}%
}
% Set the global caption style
\captionsetup{
format=margin, % Use the style previously declared
labelsep=colon,
strut=no,%
%hypcap=true, % Links point to the top of the figure
singlelinecheck=false,%
Expand Down Expand Up @@ -749,6 +750,11 @@
capbesidesep=marginparsep,%
floatwidth=\textwidth,% Width of the figure equal to the width of the text
}%
\captionsetup*[lstlisting]{%
format=llap,%
singlelinecheck=no,%
belowskip=-0.6cm,%
}%
\floatsetup[listing]{% Captions for listings (minted package)
margins=hangoutside,% Put captions in the margin
facing=yes,%
Expand All @@ -760,12 +766,6 @@
capbesidesep=marginparsep,%
floatwidth=\textwidth,%Width of the figure equal to the width of the text
}%
\captionsetup*[lstlisting]{%
format=llap,%
labelsep=space,%
singlelinecheck=no,%
belowskip=-0.6cm,%
}%
\else%
\floatsetup[figure]{% Captions for figures
margins=hangright,% Put captions in the margins
Expand Down Expand Up @@ -813,6 +813,11 @@
capbesidesep=marginparsep,%
floatwidth=\textwidth,% Width of the figure equal to the width of the text
}%
\captionsetup*[lstlisting]{%
format=llap,%
singlelinecheck=no,%
belowskip=-0.6cm,%
}%
\floatsetup[listing]{% Captions for listing (minted package)
margins=hangright,% Put captions in the margin
facing=yes,%
Expand All @@ -824,12 +829,6 @@
capbesidesep=marginparsep,%
floatwidth=\textwidth,% Width of the figure equal to the width of the text
}%
\captionsetup*[lstlisting]{%
format=llap,%
labelsep=space,%
singlelinecheck=no,%
belowskip=-0.6cm,%
}%
\fi%
}
Expand Down Expand Up @@ -867,7 +866,6 @@
}
\captionsetup*[lstlisting]{% Captions style for lstlistings
%format=margin,%
labelsep=colon,%
strut=no,%
singlelinecheck=false,%
indention=0pt,%
Expand Down

0 comments on commit 873ef2f

Please sign in to comment.