我想要创建类似下面的图像:
(我没能很好地画出章节号和字体)
和
(我没能很好地画出页码)
--------------更新根据 Gonzalo Medina 的回答----------------------
\documentclass[a4paper,12pt,oneside]{report}
\usepackage{fontspec}
\usepackage{xunicode}
\setmainfont{Times New Roman}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setotherlanguage{english}
\usepackage{fixltx2e} %to use _ and ^
\usepackage{url}
\usepackage{indentfirst}
\usepackage{wrapfig} % for wrapping graphics with text
\usepackage{float} % for images
\usepackage[a4paper,left=2cm,top=2.5cm,right=2cm,bottom=2.5cm]{geometry}
\usepackage{graphicx, amsmath, lettrine,amssymb}
\usepackage{fancyhdr,verbatim}
\usepackage{rotating,appendix}
\usepackage{ucs}
\usepackage{longtable}
\usepackage{listings}
\usepackage{caption}
\usepackage{capt-of}
\usepackage{underscore} %in order to use __
\usepackage{hyperref} % to make hyperlinks
%----------------------------for changing the chapter format-------------------
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\titleformat{\chapter}[display]
{\Huge\scshape}
{\filleft\tikz\node[fill=green!50!black!10,rectangle,rounded corners=6pt] (chap) {\chaptertitlename};}
{0ex}
{\colorbox{green!50!black!10}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\vskip1ex#1\vskip1ex}}}
%-------------------------------------------------------------------------------
\begin{document}
\thispagestyle{empty}
\renewcommand{\chaptername}{}
\newcommand{\EN}[1]{\foreignlanguage{english}{#1}} %in order to write english as \EN{Some words in English}
\addtocontents{toc}{\protect\thispagestyle{empty}} %to remove numbering the page from table of contents (ToC)
\tableofcontents
\thispagestyle{empty}
\chapter*{Preface}
\thispagestyle{empty}
\indent some text
\chapter {Chapter 1}
\textbf {\LARGE Intro}
\setcounter{page}{1}
\section {History}
\indent Some text ggttg
\section {Another}
\indent some text
\chapter {Chapter 2}
\textbf {\LARGE Two}
\section {History2}
\indent text
\end{document}
使用上述代码我收到
我想
另外,对于第二个布局,几乎相同。它显示“1:第 1 章”而不是“1:简介”。我想要的只是在每一页(每章的第一页除外)显示页码和该章的标题
答案1
以下是使用titlesec
包:根据评论,必须删除章节编号。此外,无需使用重新定义\@makechapterhead
;可以使用以下更简单的方式修改/控制所有格式方面\titleformat
:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\titleformat{\chapter}[display]
{\Huge\scshape}
{\filleft\tikz\node[fill=green!50!black!10,rectangle,rounded corners=6pt] (chap) {\chaptertitlename};}
{0ex}
{\colorbox{green!50!black!10}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\vskip1ex#1\vskip1ex}}}
\begin{document}
\chapter{A Test Chapter}
\end{document}
对于第二种布局,您可以执行以下操作(我应该提到,在章节标题中显示页码似乎有点奇怪):
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\titleformat{\chapter}[display]
{\Large\scshape}
{}{0ex}
{\colorbox{green!50!black!10}{\colorbox{green!50!black!20}{\parbox{1cm}{\thepage}}\parbox{\dimexpr\textwidth-2\fboxsep-1cm\relax}{\filcenter\vskip1ex\chaptername~\thechapter: #1\vskip1ex}}}
\begin{document}
\chapter{A Test Chapter}
\end{document}
在对原始问题添加评论后,我认为现在我知道要求了什么:以下示例显示了对章节标题格式的修改以及在 fancyhdr 包的帮助下对标题的修改:
\documentclass[a4paper,12pt,oneside]{report}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage[explicit]{titlesec}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}% just to generate filler text for the example
%----------------------------for changing the chapter format-------------------
\titleformat{\chapter}[display]
{\LARGE\scshape\bfseries}
{\filleft\tikz\node[fill=green!50!black!10,rectangle,rounded corners=6pt] (chap) {\chaptertitlename~\thechapter};}
{0ex}
{\colorbox{green!50!black!10}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\vskip1ex#1\vskip1ex}}}
%----------------------------for changing the header-------------------
\fancyhf{}
\fancyhead[L]{\colorbox{green!50!black!10}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\colorbox{green!50!black!40}{\thepage:} \leftmark}}}
\renewcommand\headrulewidth{0pt}
\setlength\headheight{24pt}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\makeatletter
\let\ps@plain\ps@empty
\makeatother
\begin{document}
\tableofcontents
\chapter {Intro}
\section {Another}
\lipsum[1-15]
\chapter {Two}
\section {History2}
\lipsum[1-15]
\end{document}