![程式碼](https://rvso.com/image/266415/%E7%A8%8B%E5%BC%8F%E7%A2%BC.png)
考慮下面的螢幕截圖。
我想要擁有的功能是:
- 我可以縮小頁面大小,並允許表格跨頁。
- 奇數行的背景必須與偶數行的背景不同,以方便閱讀。
- 這些值必須自動計算,而不是透過手動輸入資料。
微量元素
\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[nomessages]{fp}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{pgffor}
\begin{document}
\topskip=0pt
\begin{longtable}{*2{|>{$\displaystyle}c<{$}}|}\hline
\theta & \sin \theta\\
\foreach \x in {0,10,...,360}{\x & \FPeval\temp{round(\x:3)}\temp\\}
\end{longtable}
\end{document}
答案1
更容易的是,您可以使用計算機軟體包將允許您評估三角函數。還有上板狀軟體包將允許您在每個表格上重複標題/頁腳。
這是一個更簡單的例子:
程式碼
\documentclass{article}
\usepackage[nomessages]{fp}
\usepackage[table]{xcolor}
\usepackage{calculator}
\usepackage{forloop}
\usepackage{supertabular}
\usepackage{longtable}
\usepackage{fullpage}
\begin{document}
\newcounter{theangle}
\tablefirsthead{
\cline{2-4}
\rowcolor{white}
\multicolumn{1}{c|}{ } &
\cos \theta & \sin \theta & \tan \theta &
\multicolumn{1}{c}{ } \\
\hline
}
\tablehead{
\rowcolor{white}
\multicolumn{5}{c}{Table continued \ldots}\\
\cline{2-4}
\rowcolor{white}
\multicolumn{1}{c|}{ } &
\cos \theta & \sin \theta & \tan \theta &
\multicolumn{1}{c}{ } \\
\hline
}
\tablelasttail{
\rowcolor{white}
\multicolumn{1}{c|}{ } &
\cos \theta & \sin \theta & \tan \theta &
\multicolumn{1}{c}{ }\\
\cline{2-4}
}
\tabletail{
\hline
\rowcolor{white}
\multicolumn{1}{c|}{ } &
\cos \theta & \sin \theta & \tan \theta &
\multicolumn{1}{c}{ } \\
\cline{2-4}
\rowcolor{white}
\multicolumn{5}{c}{Continued on next page \ldots}\\
}
\rowcolors{2}{gray!50}{white}
\begin{center}
\begin{supertabular}{*5{|>{$}c<{$}}|}
\forloop{theangle}{0}{\value{theangle} < 360}{
\arabic{theangle}^\circ &
\DEGREESCOS{\value{theangle}}{\solx} \solx &
\DEGREESSIN{\value{theangle}}{\solx} \solx &
\DEGREESTAN{\value{theangle}}{\solx} \solx &
\arabic{theangle}^\circ\\
\addtocounter{theangle}{4}
}
\end{supertabular}
\end{center}
\end{document}
輸出
答案2
套餐
xcolor
table
可以選擇\rowcolor
pgfplotstable
(以及內部pgfmath
)用於建立整個表。該pgfmath
包幫助我們創建三角值(都是內建的)longtable
允許在一個表格中進行分頁(需要多次傳遞)siunitx
在表格中排版數字(pgfmath
在數位列印方面已經做得很好,但這不太適合表格)booktabs
為了好的規則。
\pgfplotstableset
輔助樣式
前面帶有 an 的樣式@
是我創建的新樣式。既不是@
必需的(只是為了將pgfplotstable
的樣式與我的樣式分開),也不是一成不變的名稱。這些樣式與處理程序一起使用.list
以簡化列的建立。
線路
@create function/.list={sin,cos,tan,cot,cosec,sec},
建立主列,請注意該csc
函數在 PGF 中命名cosec
。該列已命名cosec
,但我後來將其更改column name
為csc
。 (人們也可能注意到,應該使用正確的列名稱,例如$\phi$
和$\sin \phi$
而不是空列名稱和非數學模式但數學函數名稱。)
請注意string type
關鍵,這會停用 PGF 列印數字功能(但不會停用列的 PGF 數學計算)。
longtable
設定
基本鍵begin table
和end table
用於設定內部表環境從tabular
到longtable
。
此every head row
樣式(錯誤)用於設定特殊行(這些是longtable
功能)。請參閱longtable
手冊以了解更多資訊。
\pgfplotstablenew
讓我們建立 91 行(+ 標題(例如longtable
序言)):
\pgfplotstablenew[
columns={left,sin,cos,tan,cot,sec,cosec,right},
]{91}\myTable
\sisetup
某些siunitx
設定是在實際排版之前進行的(這也可以在列規範中完成S[…]
)。需要這些設置,這樣就不會嘗試以科學記數法設置數字,因為 PGF 數學可能會以(幾乎無處不在)siunitx
的形式給出輸出。1.746e-2
\pgfplotstabletypeset
最後!
column type
這裡使用了用於設定 s 的輔助樣式。
使用@secure header
巨集\multicolumn
來隱藏內容siunitx
的解析。通常的方法是將內容放在大括號中,例如,{sin}
在這裡似乎不起作用。
left
和列right
僅使用帶有附加via語法的r
列(我們S
也可以在這裡使用)。這也是標題需要空白條目的原因。\si{\degree}
array
<{…}
\multicolumn{1}{c}{}
程式碼
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{siunitx}
\usepackage{booktabs}
\pgfplotstableset{
% helpers
@create function/.style={
create on use/#1/.style={
create col/expr=#1(\thisrow{left})}},
@secure header/.style={
columns/#1/.append style={
column name=\multicolumn{1}{c}{#1}}},
@set columns to siunitx type 1/.style={
columns/#1/.append style={
string type,
column type={S[table-format=1.4]}}},
@set columns to siunitx type 2/.style={
columns/#1/.append style={
string type,
string replace={inf}{\multicolumn{1}{c}{$\infty$}},
column type={S[table-format=2.4]}}},
@set columns to siunitx type 3/.style={
columns/#1/.append style={
string type,
string replace={inf}{\multicolumn{1}{c}{$\infty$}},
column type={S[table-format=2.3]}}},
@set columns to basic style/.style={
columns/#1/.append style={
column type={r<{\si{\degree}}}}},
@set empty header/.style={
columns/#1/.append style={
column name={\multicolumn{1}{c}{}}}},
%
% the left and right columns
create on use/left/.style={
create col/expr=\pgfplotstablerow},
create on use/right/.style={
create col/expr={90-\thisrow{left}}},
%
% Let's start: the functions
@create function/.list={sin,cos,tan,cot,cosec,sec},
% The longtable setup
begin table=\begin{longtable},
end table=\end{longtable},
every head row/.append style={
before row=\toprule,
after row=%
\midrule \endhead
\midrule
\multicolumn{1}{c}{} & {cos} & {sin} & {cot} & {tan} & {csc} & {sec} & \multicolumn{1}{r}{\dots}\\ \bottomrule
\endfoot
\midrule
\multicolumn{1}{c}{} & {cos} & {sin} & {cot} & {tan} & {csc} & {sec} & \multicolumn{1}{r}{} \\ \bottomrule
\endlastfoot},
every odd row/.style={before row={\rowcolor[gray]{.9}}},
}
\pgfplotstablenew[
columns={left,sin,cos,tan,cot,sec,cosec,right},
]{91}\myTable
\begin{document}
\sisetup{scientific-notation = fixed, fixed-exponent = 0, table-auto-round=true}
\pgfplotstabletypeset[
% the column types
@set columns to siunitx type 1/.list={sin,cos},
@set columns to siunitx type 2=tan,
@set columns to siunitx type 3/.list={cot,sec,cosec},
@set columns to basic style/.list={left,right},
% setup for the headers
@secure header/.list={sin,cos,tan,cot,sec},
@set empty header/.list={left,right},
columns/cosec/.append style={column name={\multicolumn{1}{c}{csc}}},
]\myTable
\end{document}