相关文章推荐
英俊的大葱  ·  protobuf ...·  1 年前    · 
听话的显示器  ·  css ...·  1 年前    · 

合并多行/多列的代码示例

latex表格手把手超详细教程(table, tabular, multirow, multicolumn)_正则化的博客-CSDN博客_multicolumn

latex 表格间距

统一调整行距:在 tabular 环境外添加: \renewcommand\arraystretch{1.5} \linespread{1.5}

单独控制行高:每一行的换行符 \\ 后面加上 [5ex] 就能单独控制行高,其中 5 可以随意修改

小幅调整表格尺寸

Latex解决表格过宽问题,自适应调整宽度 - 知乎

使用 \resizebox{ 宽度 }{ 高度 }{ 对象 } 命令

\resizebox{\linewidth}{!}{  #此处!表示根据根据宽高比进行自适应缩放,也可以将 ! 换成自定义的 12mm 等
\begin{tabular}...
\end{tabular}
} # 注意加的位置在\begin{tabular}和\end{tabular}前后

\hsize : 是 \(\TeX\) 中定义的长度,是一种叫做水平盒子的长度,它的主要作用是告诉TeX系统什么时候换行。所以大部分时候和\textwidth是一致的,但是在分栏状况下,\hsize只是栏的宽度;
\textwidth : 是 \(\LaTeX\) 中定义的长度,等效于\hsize,并且是固定不变的,可以理解为一行文字的宽度。
\pagewidth : 包含了页边的宽度,比\textwidth要大
\linewidth : 这指得是目前环境的宽度,是依赖于上下文的一个宽度值,例如新建了一个box,在这个box中,\linewidth是box中文字的宽度。再例如minipage环境中,\linewidth就和这个minipage的大小有关.
\columnwidth : 如果文章分栏的话,这个宽度就是每一栏的宽度。

只调整宽度,高度不变:\setlength{\tabcolsep}{1.5mm}{\begin{tabular} 表格内容 \end{tabular}}

超宽表自动换行

How to automatically line-break a wide table? - TeX - LaTeX Stack Exchange

  • 第一种办法自动换行,但是需要写面条代码
  • 第二种办法手动换行,但是需要计数,可扩展性、可修改性差
  • 手动换行,但是代码写出来好看一点(大概,但我没仔细看懂)table spanning two pages in portrait format

    链接1的法一:

    \documentclass{article}
    \def\zz#1#2#3{
    \begin{tabular}[t]{l}
    \hline#2\\
    \end{tabular}
    \linebreak[0]\ignorespaces}
    \begin{document}
    \begin{center}\setlength\lineskip{10pt}
     \zz{a}{z}{one}
    \zz{b}{y}{two}
    \zz{c}{x}{three}
    \zz{d}{w}{four}
    \zz{e}{v}{five}
    \zz{f}{u}{six}
    \zz{g}{t}{seven}
    \zz{h}{s}{eight}
    \zz{i}{r}{nine}
    \zz{j}{q}{ten}
    \zz{k}{p}{eleven}
    \zz{l}{o}{twelve}
    \zz{m}{n}{thirteen}
    \zz{n}{m}{fourteen}
    \zz{o}{l}{fifteen}
    \zz{p}{k}{sixteen}
    \zz{q}{j}{seventeen}
    \zz{r}{i}{eighteen}
    \zz{s}{h}{nineteen}%:-)
    \zz{t}{g}{twenty}
    \zz{u}{f}{twenty-one}
    \zz{v}{e}{twenty-two}
    \zz{w}{d}{twenty-three}
    \zz{x}{c}{twenty-four}
    \zz{y}{b}{twenty-five}
    \zz{z}{a}{twenty-six}
    \end{center}
    \end{document}
    

    链接1的法二:(不是很懂)

    \documentclass{article}
    \usepackage{lipsum}
    \usepackage{array} % Used for table wrapping
    \usepackage{tabularx} % Used for table wrapping
    % Define a new command to hide certain columns of a table
    \newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
    \begin{document}
        \lipsum[42]
        \newcommand{\hidetableone}[1]{
        \begin{tabular}{#1}
            a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z\\ \hline
            z & y & x & w & v & u & t & s & r & q & p & o & n & m & l & k & j & i & h & g & f & e & d & c & b & a \\
            one & two & three & four & five & six & seven & eight & nine & ten & eleven & twelve &
            thirteen & fourteen & fifteen & sixteen & seventeen & eighteen & nineteen & twenty &
            twenty-one & twenty-two & twenty-three & twenty-four & twenty-five & twenty-six
        \end{tabular}
        \begin{figure}
            \centering
            \hidetableone{*{0}{H} l | *{9}{l} *{16}{H}} 
            %{0}表示本行起始元素,{9}是一行中当前列的元素个数(不算隔开的),{16}是剩余元素个数
            %第一行分成了两列,第二列希望有9个元素;一下只有一列,所以中间的参数个数等于该列中元素个数
            %字母参数意义未知
            \hidetableone{*{10}{H} *{7}{l} *{9}{H}}
            \hidetableone{*{17}{H} *{6}{l} *{3}{H}}
            \hidetableone{*{23}{H} *{3}{l} *{0}{H}}
            \caption{This is a caption for a large table.}
        \end{figure}
    \end{document}
    

    超长表分页

    Latex longtable宏包与自动续表_

    对于不宽但很长的表格可以用longtable宏包来进行分页显示。实例如下

    \usepackage{longtable}
    \usepackage{booktabs}
    \usepackage{multirow}
    		\small 
            \begin{longtable}{p{0.85cm} p{2cm} p{4.5cm} p{7.5cm}}
                \caption{因子说明}
                \label{tab-data}\\ 
                \toprule 
                序号 & 类型    & 名称  & 描述 \\ 
                \midrule  
                    \endfirsthead
                    \multicolumn{4}{r}{续表\autoref{tab-data}}\\
                    \multicolumn{4}{c}{(接上页)}\\
                    \toprule
                    序号 & 类型    & 名称  & 描述   \\
                    \midrule
                    \endhead\\
                    \bottomrule
                    \multicolumn{4}{c}{(接下页)}
                \endfoot \\
                \bottomrule
                \endlastfoot
                1  & 成长类   & \begin{tabular}[c]{@{}l@{}}净利润增长率 \\ NetProfitGrowRate\end{tabular}             & $\frac{\mbox{今年净利润}}{\mbox{去年净利润}}-1$  \\ 
                2  & 成长类   & \begin{tabular}[c]{@{}l@{}}5 年收益增长率 \\ EGRO\end{tabular}                        & $\frac{\mbox{5 年收益(年)线性回归系数}}{\mbox{5 年收益均值绝对值}}$  \\ 
                3  & 成长类   & \begin{tabular}[c]{@{}l@{}}净资产增长率 \\ NetAssetGrowRate\end{tabular}              & $\frac{\mbox{今年股东权益}}{\mbox{去年股东权益}}-1$  \\
            \end{longtable}
    

    \toprule、\midrule和\bottomrule为三线表booktabs的横线控制命令;\endfirsthead前为表格首页的表头,\endfirsthead到\endhead部分为其它页的表头,\endhead到\endfoot部分为除表格尾页外的其它页的表尾,若表格接口处需要连接提示(如实例中的“续表”“接上页”“接下页”等内容)可在上述两个部分设置,\endfoot到\endlastfoot部分是最后一页的表尾。

    最简单的使用也可不做\endhead等设置,直接使用longtable环境,这样表格也会在分页时自动断开。而插入\newpage命令能在命令插入处强制分页。需要交叉引用时label可如上所示放在caption的后面。

    需要注意的是longtable环境不能放在table的浮动体内,否则只会在一页显示。

    有时候表格的内容太多过宽,需要用小号的字,可在\begin{longtable}前加\small等控制字号的命令。但这样会一个问题:caption的内容也变小了。在caption内容前加\normalsize等字号命令虽可使内容成为大字,但前面的"表?"字样仍为小字,可通过使用caption宏包解决这一问题,在导言区加入下列命令:

    \usepackage[font=normalsize]{caption}
    \renewcommand{\normalsize}{\zihao{-4}}
    

    上述命令将caption的字号设为normalsize,同时又通过重定义\normalsize来控制caption的字号大小。

    对于又长又宽的表格,目前除了缩小字号外还不清楚是否有更好的方法,

    %导言区:\usepackage{rotfloat}
    \begin{sidewaystable}
    \centering
    \begin{tabular}{cccc}
    \end{tabular}
    \end{sidewaystable}