貓的例子

貓的例子

我一直在使用 fancyheadings 套件來設定頁腳,顯示「第 2 頁,共 3 頁」等,在我添加 tikz 套件來繪製一些圖形之前,它工作得很好。現在,除了將頁腳與文件其餘部分分開的水平線之外,頁腳根本不顯示。有沒有辦法可以享受頁尾又可以用 tikz 繪圖?

這是我的程式碼:

    \documentclass[12pt,letterpaper]{article}
    \setlength{\textwidth}{6.5in}
    \setlength{\textheight}{9.5in}
    \setlength{\oddsidemargin}{-.25in}
    \setlength{\evensidemargin}{-.25in}
    \setlength{\topmargin}{-.25in}
    \usepackage{fancyhdr}
    \usepackage{lastpage}
    \pagestyle{fancy}
    \cfoot{Page \thepage\ of \pageref{LastPage}}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{1pt}
    %\usepackage{tikz}
    \begin{document}

    \begin{center}
    \Huge  {\bf More Sets}\\
    \end{center}
    \end{document}

當我用註解掉 \usepackage{tikz} 進行編譯時,我得到了我想要的: 成功!

但是當我取消註釋 \usepackage{tikz} 時,該欄仍然存在,但較低,並且找不到頁碼: 在此輸入影像描述

答案1

fancyhdr,並且tikz完全兼容。我一直在文檔中使用這兩種方法。

但是,最好直接加載,fancyhdr因為fancyheadings無論如何都會加載它,這樣會更透明。

如果您願意,甚至可以在fancyhdr的頁首和頁尾設定巨集的參數中使用 TikZ 圖片。有關 TikZ 貓的範例,請參見下文。

您遇到的問題是由於在沒有 TikZ 的情況下,您產生的文件使用的是 A4 紙上的美國字母佈局之類的內容。 A4 紙比 US letter 更高,因此有更多空間。但基本上,事情最終都會亂七八糟。

當您載入 TikZ 時,這會載入從類別中取得的內容(不確定是什麼)letterpaper並相應地設定紙張。現在你在信紙上有了信紙佈局。但現在紙張較短,基本上沒有足夠的空間。

解決這個問題的最佳方法是加載geometry,但是您不需要對佈局尺寸進行手動調整,而是堅持提供geometry套件或配置選項。

例如:

\documentclass[12pt,letterpaper]{article}
\usepackage{geometry}
\geometry{width=6.5in,height=9.5in,left=.75in,top=.75in}
\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\cfoot{Page \thepage\ of \pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
\usepackage{tikz}
\begin{document}
\begin{center}
  \Huge\bfseries More Sets
\end{center}
\end{document}

請注意,它\bf已在 20 多年前被棄用,並且不應在該日期之後的 LaTeX 文件中使用。如果開始\documentclass,它不應該使用\bf或類似的。

另請注意,這\Huge {abc}d與 相同\Huge abcd\Huge不需要爭論。就像\bfseries,它是一個開關。

無論如何,結果如下:

缺少貓

貓的缺席很引人注目,但你不可能擁有一切,但現在一切都在頁面上。

然而,它並不像fancyhdr告訴我們的那樣真正適合:

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 14.49998pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however.

所以我們需要再次改變我們的佈局,使用geometry的介面:

\documentclass[12pt,letterpaper]{article}
\usepackage{geometry}
\geometry{width=6.5in,height=9.5in,left=.75in,top=.75in,headheight=15pt}
\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\cfoot{Page \thepage\ of \pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
\usepackage{tikz}
\begin{document}
\begin{center}
  \Huge\bfseries More Sets
\end{center}
\end{document}

最後結果:

調整後的標題高度

貓的例子

例如:

TikZ 貓可以去任何地方,任何頁首、任何頁腳...

\documentclass[welsh,british]{article}
\usepackage[rgb,x11names,dvipsnames,svgnames]{xcolor}
\usepackage{kantlipsum,tikz,fancyhdr,geometry,babel}
\geometry{headheight=40pt,footskip=60pt}
\usetikzlibrary{cathod,trambws,positioning,decorations.footprints}
\colorlet{cath1}{blue!50!gray!75}
\colorlet{cath2}{cath1!50}
\colorlet{cath3}{DarkOrchid4}
\colorlet{cath4}{cath3!50}
\colorlet{lliw llygaid1}{Yellow1}
\colorlet{lliw llygaid2}{DarkOrange3}
\colorlet{lliw llygaid3}{Chartreuse1}
\colorlet{lliw llygaid4}{Green4}
\colorlet{lliw trwyn1}{LightPink2}
\colorlet{lliw trwyn2}{HotPink2}
\colorlet{cath5}{LavenderBlush3}
\colorlet{cath6}{LavenderBlush4}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{%
  \tikz{\pic [xscale=-1] {cath eistedd={stripiau=cath1, llenwi=cath2, llygaid mewnol=lliw llygaid3, llygaid allanol=lliw llygaid4, trwyn=lliw trwyn1, maint=1mm}};}%
}
\fancyhf[rh]{%
  \tikz{\pic at (57.5mm,0) {cath eistedd={stripiau=cath3, llenwi=cath4, llygaid mewnol=lliw llygaid1, llygaid allanol=lliw llygaid2, trwyn=lliw trwyn2, maint=1mm}};}%
}
\fancyhf[cf]{%
  \begin{tikzpicture}
    \pic [xscale=-1] at (3,1.4) {cath eistedd={stripiau=cath6,llenwi=cath5,llygaid mewnol=lliw llygaid3,llygaid allanol=lliw llygaid4,trwyn=lliw trwyn2, maint=1mm}};
    \draw [line width=.5pt, rounded corners=.25pt, draw=Chocolate4] (3.5,.7) rectangle (3.6,.75);
    \draw [rounded corners=1pt, inner color=Chocolate3!95, outer color=Chocolate3, draw=Chocolate4, line width=.5pt] (3.35,.4) rectangle (3.75,.7);
    \draw [decorate, fill=Chocolate4, draw=Chocolate4, decoration={footprints, foot of=felis silvestris, foot length=.35pt, stride length=.4pt, foot angle=-30}] (3.625,.55) -- (3.525,.6);
    \draw [line width=1pt, line cap=round, draw=OliveDrab4] (4.75,1.85) -- (4.75,.25) coordinate [pos=.04] (a);
    \node [double=Green2, double distance=.25pt, draw=Green4!50!black, line width=.25pt, rounded corners=1pt, text=white, inner sep=1pt, fill=Green4, font=\sffamily\tiny\bfseries, align=center, anchor=north east] at ([xshift=1pt]a) {BUS STOP\\{\selectlanguage{welsh}SAFLE BYSIAU}};
  \pic [lliw y tram=Red2, lliw ffenestri=Snow3] at (-2,0) {tram=5};
  \end{tikzpicture}
}
\begin{document}
\kant[1-6]
\end{document}

相關內容