![使用 Titlesec 将页码和标题放在页边距上](https://linux22.com/image/384497/%E4%BD%BF%E7%94%A8%20Titlesec%20%E5%B0%86%E9%A1%B5%E7%A0%81%E5%92%8C%E6%A0%87%E9%A2%98%E6%94%BE%E5%9C%A8%E9%A1%B5%E8%BE%B9%E8%B7%9D%E4%B8%8A.png)
我想创建这个布局:
标题在黑框中,使用titlesec
。但我只得到了这个结果:
我无法向下移动页码...
这是我的代码:
\documentclass{book}
\usepackage[a4paper,right=1cm, left=1cm,bottom=1cm,top=1cm]{geometry}
\pagestyle{plain}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\pagestyle{plain}
\renewpagestyle{plain}{
\widenhead[1cm][1cm]{1.5cm}{1.5cm}
\sethead[\LARGE\bfseries\thepage][][]{}{}{\LARGE\bfseries\thepage}%
}
\newpagestyle{main}{
\widenhead[1cm][1cm]{1.5cm}{1.5cm}
\sethead[\LARGE\bfseries\thepage][][]{}{}{\LARGE\bfseries\thepage}%
}
\begin{document}
\pagestyle{main}
\chapter{Here}
\section{here}
\lipsum[1-20]
\chapter{Here}
\lipsum[1-20]
\end{document}
我尝试用 来解决问题background
,但无法阻止它遇到空白页和章节(普通)页。
答案1
可能的解决方案:
\documentclass{book}
\usepackage[a4paper,right=1cm, left=1cm,bottom=1cm,top=1cm]{geometry}
\pagestyle{plain}
\usepackage[pagestyles]{titlesec}
\usepackage[]{graphicx}
\usepackage{lipsum}
\pagestyle{plain}
\newcommand*\MoveA[2]
{%
\rlap
{%
\raisebox{-\dimexpr\headsep+\height\relax}
{%
\llap
{%
\begin{tabular}[t]{@{}c@{}}
#1\\[\medskipamount]
#2
\end{tabular}%
}%
}%
}%
}
\newcommand*\MoveB[2]
{%
\rlap
{%
\raisebox{-\dimexpr\headsep+\height\relax}
{%
\rlap
{%
\begin{tabular}[t]{@{}c@{}}
#1\\[\medskipamount]
#2
\end{tabular}%
}%
}%
}%
}
\newcommand*\OutputHeadmark
{%
\rotatebox{90}{\strut\chaptertitle}%
}
\newcommand*\MyHeadStyle
{%
\LARGE\bfseries
}
\renewpagestyle{plain}
{%
\sethead[\MyHeadStyle\MoveA{\thepage}{\OutputHeadmark}][][]
{}{}{\MyHeadStyle\MoveB{\thepage}{\OutputHeadmark}}%
}
\newpagestyle{main}
{%
\sethead[\MyHeadStyle\MoveA{\thepage}{\OutputHeadmark}][][]
{}{}{\MyHeadStyle\MoveB{\thepage}{\OutputHeadmark}}%
}
\begin{document}
\pagestyle{main}
\chapter{Here}
\section{here}
\lipsum[1-20]
\chapter{There}
\lipsum[1-20]
\lipsum[1-20]
\end{document}