我有一份纵向的文档,里面有表格,我想把它横向显示。我想让每一页的页眉和页脚都一样,页眉和页脚都显示在右侧。纵向显示时没问题,但页脚不会显示。我看过很多关于横向旋转页眉和页脚的帖子。但我仍然有以下问题 1. 横向显示时,页眉显示在底部,而不是顶部 2. 横向显示时,页眉规则不会旋转。如果能得到帮助,我将不胜感激。我的代码如下。
\documentclass[english]{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage{everypage}
\usepackage{afterpage}
\usepackage{flafter}
\usepackage{array,booktabs,tabularx} % also loads 'array' package
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of 'X' columns
\usepackage{ltablex}
\usepackage{longtable}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=12mm]{geometry}
\usepackage{lscape,graphicx}
\usepackage[absolute]{textpos}
\usepackage{fancyhdr}
\fancypagestyle{portr}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[L]{\scriptsize Project Report}
\fancyhead[R]{\scriptsize Name of Project}
\fancyfoot[RO,LE]{\scriptsize \leftmark}
}
\fancypagestyle{lscape}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[R]{%
\begin{textblock}{20}(1,5){\rotatebox{90}{\leftmark}}\end{textblock}
}
\fancyhead[L] {%
\begin{textblock}{1}(13,10.5){\rotatebox{90}{Project Report}}\end{textblock}
}
\fancyhead[R] {%
\begin{textblock}{1}(13,10.5){\rotatebox{90}{Name of Project}}\end{textblock}
}
}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}
\newlength{\hfoot}
\newlength{\vfoot}
\AddEverypageHook{\ifdim\textwidth=\linewidth\relax
\else\setlength{\hfoot}{-\topmargin}%
\addtolength{\hfoot}{-\headheight}%
\addtolength{\hfoot}{-\headsep}%
\addtolength{\hfoot}{-.5\linewidth}%
\ifodd\value{page}\setlength{\vfoot}{\oddsidemargin}%
\else\setlength{\vfoot}{\evensidemargin}\fi%
\addtolength{\vfoot}{\textheight}%
\addtolength{\vfoot}{\footskip}%
\raisebox{\hfoot}[0pt][0pt]{\rlap{\hspace{\vfoot}\rotatebox[origin=cB]{90}{\thepage}}}\fi}
\begin{document}
\thispagestyle{portr}
\noindent Test 1 2 3.
\pagebreak{}
\noindent Test 4 5 6.
\pagebreak{}
\newgeometry{hmargin=3cm,vmargin=3cm}
\thispagestyle{lscape}
\pagestyle{lscape}
\begin{landscape}
\section{Appendix 1}
\normalsize
{\renewcommand{\arraystretch}{2}%
\begin{longtable}[H]{| p{4cm} | p{4cm} | p{2cm} | p{11cm} |}
\caption{Appendix} \label{tab:appndx1}
\\\hline
\toprule
header1 & header2 & header3 & header4
\\[0.25cm]
\hline
text11
&
text12
&
text13
&
\parbox{.72\textwidth}{text140\\text141
}
\\[0.25cm]
\hline
text21
&
text22
&
text23
&
\parbox{.72\textwidth}{text240\\text241
}
\\[0.25cm]
\hline
text31
&
text32
&
text33
&
\parbox{.72\textwidth}{text340\\text341
}
\\[0.25cm]
\hline
text41
&
text42
&
text43
&
\parbox{.72\textwidth}{text440\\text441
}
\\[0.25cm]
\hline
text51
&
text52
&
text53
&
\parbox{.72\textwidth}{text540\\text541
}
\\[0.25cm]
\bottomrule
\end{longtable}
}
\pagebreak{}
\section{Appendix 2}
{\renewcommand{\arraystretch}{2}%
\begin{longtable}[H]{| p{4cm} | p{4cm} | p{2cm} | p{11cm} |}
\caption{Appendix} \label{tab:appndx2}
\\\hline
\toprule
header1 & header2 & header3 & header4
\\[0.25cm]
\hline
text11
&
text12
&
text13
&
\parbox{.72\textwidth}{text140\\text141
}
\\[0.25cm]
\hline
text21
&
text22
&
text23
&
\parbox{.72\textwidth}{text240\\text241
}
\\[0.25cm]
\hline
text31
&
text32
&
text33
&
\parbox{.72\textwidth}{text340\\text341
}
\\[0.25cm]
\hline
text41
&
text42
&
text43
&
\parbox{.72\textwidth}{text440\\text441
}
\\[0.25cm]
\hline
text51
&
text52
&
text53
&
\parbox{.72\textwidth}{text540\\text541
}
\\[0.25cm]
\bottomrule
\end{longtable}
}
\end{landscape}
\pagestyle{plain}
\end{document}
答案1
要获得示例的输出,\leftmark
您必须\pagestyle{fancy}
至少使用一次。这可能在序言中。
使用最新版本的 KOMA-Script,您可以使用软件包组合typearea
(带选项usegeometry
)并在和geometry
之间切换。然后,您可以将页面样式用于纵向和横向页面。portrait
landscape
fancy
\documentclass[english]{article}
\usepackage[usegeometry]{typearea}% load before geometry
\usepackage[a4paper,width=150mm,vmargin=25mm,bindingoffset=12mm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all header and footer fields
\fancyhead[L]{\scriptsize Project Report}
\fancyhead[R]{\scriptsize Name of Project}
\fancyfoot[RO,LE]{\scriptsize \leftmark}
\usepackage{blindtext}% only for dummy text
%\usepackage{showframe}% only to show the page layout
\begin{document}
\blinddocument
\clearpage
\KOMAoptions{paper=landscape,DIV=last}
%\newgeometry{margin=3cm}
\newgeometry{hmargin=2.5cm,bottom=25mm,height=150mm,includehead}
\fancyheadoffset{0pt}% recalculate headwidth for fancyhdr
\blinddocument
\clearpage
\KOMAoptions{paper=portrait,DIV=last}
\restoregeometry
\fancyheadoffset{0pt}
\blinddocument
\end{document}
结果: