2017年6月26日 星期一

LaTeX 常見問題

原文是這裡的簡體版 ,我稍做翻譯轉載如下:


1.\makeatletter 和 \makeatother 的用法?
答:如果需要借助於內部有\@字元的命令,如\@addtoreset,就需要借助於另兩個命令
\makeatletter, \makeatother。
下面給出使用範例,用它可以實現公式編號與節號的關聯。
\begin{verbatim}
\documentclass{article}
...
\makeatletter % '@' is now a normal "letter" for TeX
\renewcommand\theequation{\thesection.\arabic{equation}}
\@addtoreset{equation}{section}
\makeatother % '@' is restored as a "non-letter" character for TeX
\begin{document}
...
\end{verbatim}

2.比較一下CCT與CJK的優缺點?
答:根據王磊的經驗, CJK 比 CCT 的優越之處有以下幾點:
1) 字體定義採用 LaTeX NFSS 標準,生成的 DVI 檔不必像 CCT 那樣需要用 patchdvi 處理後才能預覽和列印。而且一般 GB 編碼的檔也不必進行預處理就可直接用 latex 編譯。
2) 可使用多種 TrueType 字體和 Type1 字體,生成的 PDF 檔更清楚、漂亮。
3) 能同時在文章中使用多種編碼的文字,如中文簡體、繁體、日文、韓文等。
當然,CCT 在一些細節上,如字體可用中文字型大小,字距、段首縮進等。畢竟 CJK 是老外作的嗎。
談到 MikTeX 和 fpTeX, 應該說談不上誰好誰壞,主要看個人的喜好了。 MikTeX 比較小,不如 fpTeX 裏提供的 TeX 工具,宏包全,但一般的情況也足夠了。而且 Yap 比 windvi 要好用。fpTeX 是 teTeX 的 Windows 實現,可以說各種 TeX 的有關軟體基本上都包括在內。

3.中文套裝中如何加入新的.cls文件?
答:放在tex檔的同一目錄下,或者miktex/localtexmf/tex/latex/下的某個子目錄下,可以自己建一個。

4.怎樣象第幾章一樣, 將參考文獻也加到目錄?
答:在參考文獻部分加入
\addcontentsline{toc}{chapter}{參考文獻}
語句即可

5.對於A4的紙型參數,如何使PDFLaTeX按照指定的letter輸出?
答:設置參數letterpaper \usepackage[letterpaper]{geometry}

6.如何改變題注或註腳的標號?
答:重新定義\maketitle或者直接修改article.cls中的“\renewcommand\thefootnote\@fnsymbol\c@footnote}%”這句話。

7.怎麼給CJKnumber付初值?
答:計數器都是這樣賦值的 \setcounter{\CJKnumber}{value}

8.怎樣才能使Winedt錯誤關聯?
答:"C:\?????\winedt\winedt.exe" "[Open('%f');SelLine(%l,8)]"

9.如何改變Reference的大小?
答:\renewcommand\refname{\begin{CJK*}{GB}{song}\small參考文獻\end{CJK*}}

10.如何拷貝PDF和PS檔中的圖片?
答: Adobe Acrobat中有專門的命令-“文件”-“導出”-“提取圖像為”。。。當然用選中區域再拷貝的方法也可以。實際上ps檔本身就可以被不少的圖像處理軟體打開,然後就可以直接轉換了。對於不支援ps檔的圖像處理軟體,則可以把ps檔轉存為eps檔,eps檔幾乎可以被所有的圖像/圖形處理軟體打開。

11.在左邊列出輸入的命令,在右邊列出輸出的排印結果,應該用什麼命令?
答:分欄,然後用
\begin{verbatim}
Text
\end{verbatim}
如果做成表格形式,用\verb=Text=

12.如何用數位而非特定符號分段落?
答:用\enumerate

13.如何在參考文獻加入註腳?
答:例如
\begin{thebibliography}{0}
\bibitem{companion} M.~Goossens, F.~Millelbach, and A.~Samarin, ``The
\LaTeX\ Companion'', Addison--Wesley, 1994 \footnote{test of footnote}
\end{thebibliography}

14.如何在章節、標題上加註腳?
答:使用\protect\footnote{....}命令,也可用\usepackage[stable]{footmisc}

15.正文中實現單欄到雙欄,雙欄到單欄的版式的混排,而且不換頁,請問如何實現? 答:\usepackage{multicol}
\begin{document}
...
\begin{multicol}{2}
\end{multicol}
...
\end{document}

16.輔助的Package放到哪個目錄下?
答:不過非 miktex 自帶的包最好放在 localtexmf 下,這樣以後升級的時候方便些。

17.如何用fancyhdr宏包實現在頁眉下畫一粗一細兩條橫線?
答:試試下麵的命令: \usepackage{fancyhdr}
\newcommand{\makeheadrule}{%
\makebox[0pt][l]{\rule[.7\baselineskip]{\headwidth}{0.8pt}}%
\rule[.6\baselineskip]{\headwidth}{0.4pt}\vskip-.8\baselineskip}
\makeatletter \renewcommand{\headrule}{%
{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi \makeheadrule}}\makeatother
\begin{document}
\pagestyle{fancy}
....
\end{document}

18.能不能改變Chapter 起始頁碼僅從奇數頁開始?
答:用 \documentclass[openany]{book} 讓 \chapter 可以從任何頁面開始。

19.如何在文中實現帶圈的數位?
答:1)使用\textcircled{}命令,後面的參數可以是一個字元或者漢字(配合CJK),甚至也可以是公式,但是它只會給第一個字元或者漢字加上 > 合適的圓圈,字體放縮命令對它也有效,因此可以利用這點實現兩個字元加圈的效果,但是需要仔細的調整尺寸,參考如下命令: > \Large{\textcircled{\small{12}}}、\textcircled{九}。
2)使用pifont宏包,那裏面有很漂亮的帶圈的各種數位記號(僅限於阿拉伯數字,如果想使用加圈的中文“一”至“九”就不行了)。在.tex > 文件中嘗試下列命令:\ding{172}~\ding{211}。
3)在GB和GBK字形檔中本來就有10個加圈數位形式,可以直接在CJK中使用。如果不超過11的話應該夠用了呵呵:①②③④⑤⑥⑦⑧⑨⑩,這些漢 > 字可以直接使用數位軟鍵盤輸入(以智慧ABC輸入法為例,其實大部分輸入法都是一樣的):打開軟鍵盤,選擇“數位序號”即可看到。

20.如何產生可變長的 Longrightarrow?
答:用\xleftarrow and \xrightarrow,例如
\[0 \xleftarrow[\zeta]{\alpha}
F\times\triangle[n-1]
\xrightarrow{\partial_0\alpha(b)}
E^{\partial_0b}
\]

21.如何在公式中表示上下堆積關係?
答:在latex有一個命令\stackre{上部符號}{下部符號},但更好的一個是用宏包amslatex中命令\overset和\underset。一個例子是
\[ \overset{*}{X} \qquad
\underset{*}{X} \qquad
\overset{a}{\underset{b}{X}} \]

============

1。怎樣在多欄環境中使用單欄圖表?
答:如果你在多欄環境中使用 \begin{figure} ... \end{figure}, 圖形是不會出現的。如果你用另外的命令 \begin{figure*} ... \end{figure*}, 圖形就會超出右邊或有頁的上邊。解決的方法是把下面命令放在 \begin{document}前面
\makeatletter
\newenvironment{tablehere}
{\def\@captype{table}}
{}
\newenvironment{figurehere}
{\def\@captype{figure}}
{}
\makeatother
然後用 figurehere 和 tablehere 在你平常用 figure[h....] 和 table[h...]的地方。

2。怎樣得到度(degree)的符號?
答:在\begin{document} 前面用 \newcommand{\grad}{\ensuremath{^{\circ}}} ,然後你在文中就可用 45\grad等等了。

3。怎樣得到一個歐元符號?

答:用\usepackage{textcomp} 和 \texteuro 或 \usepackage{marvosym} 和 \EUR都可以。

4。當我應用fancyhdr時,我得到了太多'Overfull \vbox' 的資訊?
答:這是因為缺省的標題空間太小的原因(文本的一行),不能包括fancy標題(1 line of text + 1 rule)。在導言裏面加\addtolength{\headheight}{2.5pt}即可。

5。當我用 fancyhdr時,左邊和右邊的題有交叉重合?
答:這是因為\section 等命令中的文本太長的原因,可用類似"\section[short version]{very long version indeed}"來解決問題。

6。怎樣從兩欄頁面中得到單欄的標題和摘要?
答:試試Donald Arseneau的
\documentclass{article}
....
\begin{document}
\twocolumn[
\begin{@twocolumnfalse}
\maketitle
\begin{abstract}
...
\end{abstract}
\end{@twocolumnfalse}
]

7。怎樣改變只有幾行文本的頁邊距?
答:把以下命令放在\begin{document}前面
\newenvironment{narrow}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}
然後 \begin{narrow}{1.0in}{0.5in} ... \end{narrow} 就產生了左邊縮小1.0 英寸 和右邊縮小 0.5 英寸的效果

8。我的文本在開始時就停止不編譯?
答:這是因為每一次文本編譯時都有對應的*.aux檔(前一次產生的),所以刪去這個檔重新編譯即可。

9。在eps上加公式的另一個方法。
答:1)建一個eps圖形;
2)在你所想放置的地方寫下文本(如公式);
3)在latex文本中用命令 \usepackage{psfrag} ;
4)用命令 \psfrag{formula}{some text $\sum_1^\infty \int \frac{a^2}{b_i}$ }讓latex為做工作。
例如
\documentclass[12pt]{article}
\usepackage{psfrag}
\usepackage{epsfig}

\begin{document}
\begin{figure}
\begin{center}
\psfrag{formula1}{some text $\sum_1^\infty \int \frac{a^2}{b_i}$}
\psfrag{formula2}{other text $\int_0^{\frac{a^2}{b}} \sqrt{c}$}
\epsfig{file=example.eps, width=12cm}
\end{center}
\caption{The example figure}
\label{exampl}
\end{figure}
\end{document}

10。怎樣把一個大表格橫向放置?
答:用宏包\usepackage{rotating},然後變換
\begin{table}
....
\end{table}

\begin{sidewaystable}
....
\end{sidewaystable}

注意這個旋轉很可能在你的預覽中不會再現。

11。關於itemize。
答: 清單至多有四級

$\bullet$ - \labelitemi
\textbf{ --} - \labelitemii
$\ast$ - \labelitemiii
$\cdot$ - \labelitemiv
你可重新定義
\def{\labelitemi}{$\spadesuit$}
\renewcommand{\labelitemi}{$\spadesuit$}

也可在itemize 環境中\item命令中同時擁有不同的標籤

\begin{itemize}
\item[$\heartsuit$] ...
\item[$\diamondsuit$] ...
\item[$\clubsuit$] ...
\end{itemize}

數位序列至多四級順序可顯示,如

1,2 ... - \enumi
(a), (b) ... - \enumii
i,ii,... - \enumiii
A., B. ... - \enumiv

你也可指明選項,如
\begin{enumerate}
\item[(1)]
\item[(2)] ...
\end{enumerate}

12。我怎樣重新定義items之間的距離?
答:用miktex2.1中的mdwlist宏包,也可從CTAN的macros/latex/contrib/supported/mdwtools.zip 上下載後。

13。怎樣改變行距?
答:用doublespace宏包,參數"coef"是\baselinestretch文本中定義數值,則可用命令
\begin{spacing}{coef} % coef=2 時雙倍行距了
... text
\end{spacing}

14。 怎麼定義一個定理型環境?
答:用theorem宏包,例子:
\newtheorem{howto}{Questions}[section]
\theoremstyle{change}
\theorembodyfont{\itshape}
\theoremheaderfont{\scshape}

15。怎樣在latex中包括一每列的原始檔案?
答:例如
\floatstyle{boxed}
\restylefloat{figure}
\begin{figure}[hb]
\begin{listing}{1}
#i nclude <stdio.h>
int main(int argc, char **argv)
{
int i;
for (i = 0; i < argc; ++i)
printf("argv[%d] = %s\n", i, argv[i]);
return 0;
}
\end{listing}
\caption{A numbered C program}
\end{figure}


16。怎樣把附錄A中的公式序號變為 A.1, A.2, .... B.1, B.2, ...的形式?
答: \appendix
\makeatletter
\renewcommand\theequation{A.\@arabic\c@equation }
\makeatother
\setcounter{equation}{0}
或者 \renewcommand{\theequation}{A.\arabic{equation}}


17。怎樣把一個 \vertatim 放入 verbatim環境中?
答:用fancyvrb宏包定義自己的 verbatim環境。


18。怎樣改變主文本中的字體?
答:命令: \textnorml;申明: \normalfont\ttfamiliy


19。怎樣定義一個命令或申明 ?
答:例如一個命令: \newcommand{\name}{1]{\textsc{#1}}
一個申明: \newcommand{\name}{1]{{\normalfont\scshape #1}}


20。怎樣合併字體命令?
答: \textrm{...} {\rmfamily...} roman familiy
\textsf{...} {\sffamliy...} sans serif family
\texttt{...} {\ttfamily...} typewritter family
\textmd{...} {\mdserier...} medium series
\textbf{...} {\bfseries...} bold series
\textup{...} {\upshape...} upright shape
\textit{...} {\itshape...} italic shape
\textsl{...} {\slshape...} slanted shape
\textsc{...} {\scshape...} small caps shape
size \tiny \scriptsize \footnotesize \small \normalsize \large
\Large \LARGE \huge \Huge
\emph{...} {\em ...} emphasized
\textnormal{...} {\normalfont...} document font


21。 怎樣在頁眉和頁腳中劃一道橫線?
答:用 fancyhdr宏包。


22。怎樣改變章節字體(section fonts)?
答:用titlesec宏包,例如
\usepackage[nops,sf,small,compact]{titlesec}


23。怎樣做一個頁面設置?
答: \usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} %clear all fields
\fancyhead[RO, LE]{\bfseries \LaTeXe{} HOWTO}
\fancyfoot[LE, RO]{\thepage\ of \pageref{LastPage}}
\fancyfoot[LO, CE]{}
\fancyfoot[CO, RE]{Techical Report}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

24。怎樣實現"page M of N"的形式?
答:用lastpage宏包,任何時候你都可在文本中用 \pageref{LastPage},只是須注意當用了fancyhdr巨集包時,lastpage巨集包就須在它後面。


25。怎樣實現下劃線的標題?
答: \def\@evenhead{\makebox[0pt][l]{\rule[-0.15cm]{\textwidth}{0.1mm}}\hbox{}%

\textbf\thepage\hfil\leftmark}%

\def\@oddhead{\makebox[0pt][l]{\rule[-0.15cm]{\textwidth}{0.1mm}}\hbox{}%
{\rightmark}\hfil\textbf\thepage}%
26。 怎樣把一個浮動物件固定下來?
答:例如
\begin{figure}[h]
...
\end{figure]


27。怎樣定義一個新的浮動 "float" 形式?
答:用float宏包,用\newfloat就可定義新的浮動形式,它的語法是:
\newfloat{type}{placement}{ext}{within}
- type 是浮動新類型名
- placement 可以是 t, b, p, h 和 H
- ext 是以章節列序的任何圖表的尾碼名
\floatstyle{style}, 其中 style 可以是
- plain, 空白
- boxed, 盒子
- ruled,
\floatname{float}{floatname}
定義了浮動標題名,像圖的 "Figure" 等等。
\restylefloat{float}用於改變圖表的標準浮動形式,例如可以
\floatstyle{ruled}
\restylefloat{table}
一個例子是:
\documentclass{article}
\usepackage{float, times}
\thispagestyle{empty}
\floatstyle{ruled}
\newfloat{Program}{thp}{lop}[section]
\floatstyle{boxed}
\newfloat{algorithm}{thp}{loa}
\floatname{algorithm}{Algorithm}
\begin{document}
\section{Let's begin}
This document show some possibilities of \texttt{float.sty}
for floating objects.
\begin{Program}
\begin{verbatim}
#i nclude <stdio.h>
int main(int argc, char **argv)
{
int i;
for (i = 0; i < argc; ++i)
printf("argv[%d] = %s\n", i, argv[i]);
return 0;
}
\end{verbatim}
\caption{A simple C program}
\end{Program}
....
\end{document}


28。 怎樣讓文字在一個窄小的浮動圖周圍?
答:用floatfig巨集包,其改進巨集包是floatflt巨集包。語法是 \begin{floatingfigure}[options]{width of figure}
figure contents
\end{floatingfigure}
一個例子是:
\documentclass{article}
\usepackage{floatfig, epsfig}
...bla bla bla
\par
\begin{floatingfigure}{6cm}
... anything possible in figure environment
\end{floatingfigure}
後面的文本將會和浮動圖形平行 ,可惜floatfig宏包不是Miktex自帶的。

也可用 <wrapfigure> 巨集包,語法為
\begin{wrapfigure}[nlines]{placement}{width}figure, caption, etc.
\end{wrapfigure}
- nlines定義了文本折行為,每一個方程占3行。
- placement水準位置(l,r)
- width圖形寬度
一個例子是
\begin{wrapfigure}{r}{3in}
\begin{boxit}
\begin{center} This is a "wrapfigure" \end{center}
\caption{A wrapfigure example}
\end{boxit}
\end{wrapfigure}
注意, wrapfigure 是不浮動的,所以它可能和浮動圖形的順序就不一樣了,並且它不能在“列表list”中,詳見王磊的插圖指南。
也可用 picins 宏包,命令是
\parpic(width,height)(x-off,y-off)[Options][Position]{Picture}
段落文本
除了 Picture 以外所有的命令都是可選的,詳見王磊的插圖指南。

29。怎樣使圖形並列?
答:用subfigure宏包。
一個例子是 \begin{figure}
\centering
\mbox{ \subfigure[Big]{\includegraphics ...} \quad
\subfigure[Small]{\includegraphics ...} \quad
\subfigure[Medium]{\includegraphics ...} \quad }
\caption{Three subfigures}
\label{fig:subfigures}
\end{figure}

30。把一幅 .eps 橫向放置後,怎樣使標題變為相應的形式?
答: \usepackage{rotating}

\begin{sidewaysfigure}\centering
\includegraphics[width=?cm]{*.eps}
\caption{...}
\end{sidewaysfigure}

沒有留言:

張貼留言