考虑以下 MWE:
\documentclass[12pt,twoside,letterpaper]{report}
\usepackage[text={4.95in,7.5in},centering,bottom=1.5in,showframe]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{calc}
\usepackage[explicit]{titlesec}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,positioning}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\evensidemargin}{1.75in}
\DeclareFixedFont{\chapterfont}{T1}{ppl}{m}{n}{0.365in}
\DeclareFixedFont{\chapternumfont}{T1}{ppl}{m}{n}{1in}
%-------------------------------------------------------------------------
% Chapter Style
%-------------------------------------------------------------------------
\titleformat{\chapter}[display]
{\chapterfont}
{
\ifodd\thepage
\begin{tikzpicture}[overlay, remember picture]
\node[minimum width=2.5in, text width=\marginparwidth+\evensidemargin-2\marginparsep+\oddsidemargin, minimum height=10pt, rectangle, fill=cyan, outer sep=0pt, anchor=north east, align=right] at ($(current page.north east)$) {};
\node[text=cyan](chapnum) at ($(current page.north east)+(-2\marginparwidth+2.85\marginparsep,-1.125in)$) {\chapternumfont\thechapter};
\node[cyan,outer sep=0pt,left=0em of chapnum] (vline) {$\left|\vphantom{\text{\chapternumfont 1}}\right.$};
\end{tikzpicture}%
\else
\begin{tikzpicture}[overlay, remember picture]
\node[minimum width=2.5in, text width=\marginparwidth+\evensidemargin-2\marginparsep+\oddsidemargin, minimum height=10pt, rectangle, fill=magenta, outer sep=0pt, anchor=north west, align=right] at ($(current page.north west)$) {};
\node[text=magenta](chapnum) at ($(current page.north west)+(2\marginparwidth-2.85\marginparsep,-1.125in)$) {\chapternumfont\thechapter};
\node[magenta,outer sep=0pt,right=0em of chapnum,at=(chapnum.east)] (vline) {$\left|\vphantom{\text{\chapternumfont 1}}\right.$};
\end{tikzpicture}%
\fi
}
{-2.125in}
{\parbox{0.85\textwidth}{#1}}
[\vspace*{.35in}]
%-------------------------------------------------------------------------
% Chapter Page Header/Footer
%-------------------------------------------------------------------------
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyfoot[RO]{\thepage$|$}
\fancyfoot[LE]{$|$\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
%-------------------------------------------------------------------------
% Header/Footer Page Styles
%-------------------------------------------------------------------------
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyfoot[RO]{\thepage$|$}
\fancyfoot[LE]{$|$\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}
\begin{document}
\chapter{L'Hopitals Rule}
\ifodd\thepage
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north west] at (current page marginpar area.north west) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north east] at (current page marginpar area.north east) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\fi
test\footnote{test}
\lipsum[1-2]
\lipsum
\chapter{Descartes Rule of Signs}
\ifodd\thepage
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north west] at (current page marginpar area.north west) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north east] at (current page marginpar area.north east) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\fi
\lipsum[1-2]
\chapter{Mean Value Theorem and Intermediate Value Theorem}
\lipsum[1-2]
\end{document}
得出:
如您所见,我面临几个优化问题:
- 章节样式可能未正确定义。
- 章节编号旁边的垂直线未与其上方的水平线正确对齐。
- 章节名称(如洛必达法则)没有与竖线正确垂直居中。这在第三幅图中很明显。
- 章节名称后的文本开始位置有垂直位移,这在第三幅图中显而易见。
- 页面的几何形状定义不正确。我只想要一张普通的信纸大小的纸张,其输出与图片所示大致相同。
我正在考虑为这个模板定义以下内容:
- 能够在属于该章节的每一页中放置水平条。可能在奇数页的右侧放置垂直条,从
current page.north east
一英寸开始向下移动。 - 能够为每个章节定义不同的颜色。
- 通过在序言中使用宏,可以放置不同的图像和不同的页面。类似:
\pagepic{<pagenum>}{pic}
。这需要按图示放置。请注意,图像将使用演示中指示的空间。每页一张图片。
任何建议都将不胜感激。我这样做只是为了休闲。只是想学习新的技巧和优化技术。
答案1
您的代码没有优化。我也没有太多时间进行进一步的优化。但我做了一些修改。看看它是否看起来更好。
\documentclass[12pt,twoside,letterpaper]{report}
\usepackage[text={4.95in,7.5in},centering,bottom=1.5in,showframe]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{calc}
\usepackage[explicit]{titlesec}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{tikzpagenodes}
\usepackage{anyfontsize}
\usetikzlibrary{calc,positioning}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\evensidemargin}{1.75in}
\newcommand{\chapterfont}{%
\fontencoding{T1}
\fontfamily{ppl}
\fontseries{m}
\fontshape{n}
\fontsize{26}{28}\selectfont}
\newcommand{\chapternumfont}{%
\fontencoding{T1}
\fontfamily{ppl}
\fontseries{m}
\fontshape{n}
\fontsize{60}{60}\selectfont}
\newcommand{\chapterpicture}{%
\ifodd\thepage
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt,inner sep=0pt]
\node[anchor=north west] at (current page marginpar area.north west) {\includegraphics[height=\textheight,width=\marginparwidth,keepaspectratio]{figure}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt,inner sep=0pt]
\node[anchor=north east] at (current page marginpar area.north east) {\includegraphics[height=\textheight,width=\marginparwidth,keepaspectratio]{figure}};
\end{tikzpicture}
\fi}
%-------------------------------------------------------------------------
% Chapter Style
%-------------------------------------------------------------------------
\titleformat{\chapter}[display]
{\chapterfont}
{
\ifodd\thepage
\begin{tikzpicture}[overlay, remember picture]
\coordinate (aux1) at ($(current page.north east)-(0,10pt)$);
\coordinate (aux2) at ($(current page text area.east)+(\marginparsep,0)$);
\coordinate (aux3) at (aux2|-aux1);
\coordinate (aux4) at ($(current page marginpar area.north west)!0.5!(current page marginpar area.north east)$);
\path[fill=cyan] (aux3) rectangle (current page.north east) node [midway] (barabove) {};
\node[text=cyan,font=\chapternumfont,yshift=3cm] at (aux4) (chapnum) {\thechapter};
\node[cyan,outer sep=0pt,inner sep=0pt] (vline) at (aux3|-chapnum) {$\left|\vphantom{\text{\chapternumfont 1}}\right.$};
\end{tikzpicture}%
\else
\begin{tikzpicture}[overlay, remember picture]
\coordinate (aux1) at ($(current page.north west)-(0,10pt)$);
\coordinate (aux2) at ($(current page text area.west)-(\marginparsep,0)$);
\coordinate (aux3) at (current page.north west-|aux2);
\coordinate (aux4) at ($(current page marginpar area.north west)!0.5!(current page marginpar area.north east)$);
\path[fill=magenta] (aux1) rectangle (aux3) node [midway] (barabove) {};
\node[text=magenta,font=\chapternumfont,yshift=3cm] at (aux4) (chapnum) {\thechapter};
\node[magenta,outer sep=0pt,inner sep=0pt] (vline) at (aux3|-chapnum) {$\left|\vphantom{\text{\chapternumfont 1}}\right.$};
\end{tikzpicture}%
\fi
}
{-2.125in}
{
\begin{tikzpicture}[overlay, remember picture]
\node [align=left,text width=\textwidth,anchor=west] at (current page text area.west|-chapnum) {#1};
\end{tikzpicture}
}
[\vspace*{.35in}]
%-------------------------------------------------------------------------
% Chapter Page Header/Footer
%-------------------------------------------------------------------------
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyfoot[RO]{\thepage$|$}
\fancyfoot[LE]{$|$\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
%-------------------------------------------------------------------------
% Header/Footer Page Styles
%-------------------------------------------------------------------------
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyfoot[RO]{\thepage$|$}
\fancyfoot[LE]{$|$\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}
\begin{document}
\chapter{L'Hopitals Rule}
test\footnote{test}\chapterpicture
\lipsum[1-2]
\chapter{Descartes Rule of Signs}\chapterpicture
\lipsum[1-2]
\chapter{Mean Value Theorem and\\ Intermediate Value Theorem}
\lipsum[1-2]
\setcounter{chapter}{10}
\chapter{Other test}\chapterpicture
\lipsum[1-2]
\setcounter{chapter}{100}
\chapter{Other test}\chapterpicture
\lipsum[1-2]
\end{document}