考虑一下这个MWE:
\documentclass{book}
\usepackage{lipsum}
\usepackage{titletoc}
\usepackage{tikz}
%\usepackage{shapes.misc}
\titlecontents{psection}[2.3em]
{\large}{\contentslabel{2.3em}}{}{\tikz \node[draw,inner sep=2pt,rounded corners,fill=red!30]{@\contentspage};}
%draw,inner sep=2pt,rounded corners,fill=red!30
\begin{document}
\tableofcontents
\chapter{Chp 1}
% list of sections
\startcontents[chapters]
\printcontents[chapters]{p}{1}{}
\section{Sec 1}
\lipsum[1-2]
\section{Sec 2}
\lipsum[1-3]
\section{Sec 3}
\lipsum[1]
\chapter{Chp 2}
% list of sections
\startcontents[chapters]
\printcontents[chapters]{p}{1}{}
\section{Sec 1}
\lipsum[1-2]
\section{Sec 2}
\lipsum[1-3]
\section{Sec 3}
\lipsum[1]
\end{document}
我想让页码的样式变成如图所示的彩色填充矩形。我该怎么做?
答案1
您应该使用\thecontentspage
仅包含未格式化的页码,可以在 Ti 内部使用钾z节点:
\documentclass{book}
\usepackage{lipsum}
\usepackage{titletoc}
\usepackage{tikz}
\titlecontents{psection}[2.3em]
{\large}{\contentslabel{2.3em}}{}{\hspace*{.5em}\tikz[baseline]{\node[draw, inner sep=2pt, rounded corners, fill=red!30, anchor=base]{\thecontentspage};}}
\begin{document}
\tableofcontents
\chapter{Chp 1}
% list of sections
\startcontents[chapters]
\printcontents[chapters]{p}{1}{}
\section{Sec 1}
\lipsum[1-2]
\section{Sec 2}
\lipsum[1-3]
\section{Sec 3}
\lipsum[1]
\chapter{Chp 2}
% list of sections
\startcontents[chapters]
\printcontents[chapters]{p}{1}{}
\section{Sec 1}
\lipsum[1-2]
\section{Sec 2}
\lipsum[1-3]
\section{Sec 3}
\lipsum[1]
\end{document}