在下面给出的代码中,由于我选择使用的文本,章节标题周围的框发生了变化:
我怎样才能让所有章节标题周围的框保持固定高度并在框中(垂直)居中?谢谢您的帮助。
以下是代码:
\documentclass{book}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{calc}
\usepackage[english]{babel}
\usepackage[explicit]{titlesec}
\usepackage{charter}
\usepackage[sc,osf]{mathpazo}
\usepackage{tikz}
\usetikzlibrary{calc,shadows.blur,shapes.symbols}
\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{ocre}{RGB}{243,102,25}
\makeatletter
\renewcommand{\@chapapp}{Problem}
\makeatother
\makeatletter
\def\@makechapterhead#1{%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (.2,0) {};
\draw[anchor=west] (\Gm@lmargin+0cm,-4.8cm) node { %
{\begin{tikzpicture}
\node[draw=none,shade,
top color=mybluei,
bottom color=mybluei,
rounded corners=6pt,
blur shadow={shadow blur steps=6}
]{\color{white}\fontsize{50}{120}\itshape\rmfamily\chaptertitlename \selectfont\thechapter};
\end{tikzpicture}}
};
\end{tikzpicture}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (.2,0) {}
\draw[anchor=west] (\Gm@lmargin+1cm,-4.62cm) node { %
\parbox[b]{70pt}{\colorbox{mybluei}{%
\parbox[b][60pt][t]{44pt}{\centering%
\color{white}%
{\itshape\rmfamily\small\chaptertitlename}%
\vfill{\fontsize{50}{120}\selectfont\thechapter}%
}%
}%
}\hspace{15pt}%
\parbox[b]{\dimexpr\textwidth-150pt}{%
\raggedright\scshape#1\vskip6pt%
}%
};
\end{tikzpicture}};
\end{tikzpicture}
\fi\fi\par\vspace*{270\p@}\stepcounter{chapshift}}}
\makeatother
\pagestyle{plain}
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
\newcommand\BoxColor{ocre!60}
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
\usepackage{etoolbox,fancyhdr}
\begin{document}
\chapter{Problem 1}
\section{Paragraphs of Text}\index{Paragraphs of Text}
\lipsum[1]
\chapter{Problem 3}
\section{Paragraphs of Text Two}\index{Paragraphs of Text}
\lipsum[1]
\chapter{Problem 4}
\section{Paragraphs of Text Two}\index{Paragraphs of Text}
\lipsum[1]
\end{document}
答案1
这可以帮助你:我使用 tcolorbox 包
\documentclass{book}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{calc}
\usepackage[english]{babel}
\usepackage[explicit]{titlesec}
\usepackage{charter}
\usepackage[sc,osf]{mathpazo}
\usepackage{tikz}
\usetikzlibrary{calc,shadows.blur,shapes.symbols}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{ocre}{RGB}{243,102,25}
\titleformat{\chapter}%
{\itshape\rmfamily\Huge\color{white}}%
{}
{1em}
{%
\begin{tcolorbox}[enhanced, hbox, notitle,%
colback=mybluei, coltext=white, colframe=mybluei,%
equal height group=chaptitle,%
]
#1
\end{tcolorbox}
}
\pagestyle{plain}
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
\newcommand\BoxColor{ocre!60}
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
\usepackage{etoolbox,fancyhdr}
\begin{document}
\chapter{Problem 1}
\section{Paragraphs of Text}\index{Paragraphs of Text}
\lipsum[1]
\chapter{Problem 3}
\section{Paragraphs of Text Two}\index{Paragraphs of Text}
\lipsum[1]
\chapter{Problem 4}
\section{Paragraphs of Text Two}\index{Paragraphs of Text}
\lipsum[1]
\end{document}