我有一张表格,宽度可以但高度不行。我该如何将其拆分成两个不同的页面?我尝试使用 longtable,但出现了很多错误。
我把网上拍的长表的例子放在这关联
我也把代码放在这里
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\title{Your Paper}
\author{You}
\date{\today}
\begin{document}
\maketitle
\begin{table}[h]
\begin{tabularx}{\linewidth}{|X|X|X|}
\hline
\textbf{Screen Charateristics} & \textbf{Qualifier} & \textbf{Description} \\ \hline
\multirow{4}{*}{Size} & small & Resources for small size screens. \\ \cline{2-3}
& normal & Resources for normal size screens. (This is the baseline size.) \\ \cline{2-3}
& large & Resources for large size screens. \\ \cline{2-3}
& xlarge & Resources for extra-large size screens. \\ \hline
\multirow{8}{*}{Density} & ldpi & Resources for low-density (ldpi) screens (~120dpi). \\ \cline{2-3}
& mdpi & Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.) \\ \cline{2-3}
& hdpi & Resources for high-density (hdpi) screens (~240dpi). \\ \cline{2-3}
& xhdpi & Resources for extra-high-density (xhdpi) screens (~320dpi). \\ \cline{2-3}
& xxhdpi & Resources for extra-extra-high-density (xxhdpi) screens (~480dpi). \\ \cline{2-3}
& xxxhdpi & Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above. \\ \cline{2-3}
& nodpi & Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density. \\ \cline{2-3}
& tvdpi & Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a ``primary'' density group. It is mostly intended for televisions and most apps shouldn't need it-providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi. \\ \hline
Orientation & land & Resources for screens in the landscape orientation (wide aspect ratio). \\ \hline
& port & Resources for screens in the portrait orientation (tall aspect ratio). \\ \hline
\multirow{2}{*}{Aspect Ratio} & long & Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration. \\ \cline{2-3}
& notlong & Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration. \\ \hline
\end{tabularx}
\caption{Resolution suffixes}
\label{table:ressuffixes}
\end{table}
\end{document}
答案1
该表似乎很容易使用,因为longtable
:
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\title{Your Paper}
\author{You}
\date{\today}
\begin{document}
\maketitle
\begin{longtable}{|l|l|p{5.5cm}|}
\hline
\textbf{Screen Charateristics} & \textbf{Qualifier} & \textbf{Description} \\ \hline
\multirow{4}{*}{Size} & small & Resources for small size screens. \\ \cline{2-3}
& normal & Resources for normal size screens. (This is the baseline size.) \\ \cline{2-3}
& large & Resources for large size screens. \\ \cline{2-3}
& xlarge & Resources for extra-large size screens. \\ \hline
\multirow{8}{*}{Density} & ldpi & Resources for low-density (ldpi) screens (~120dpi). \\ \cline{2-3}
& mdpi & Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.) \\ \cline{2-3}
& hdpi & Resources for high-density (hdpi) screens (~240dpi). \\ \cline{2-3}
& xhdpi & Resources for extra-high-density (xhdpi) screens (~320dpi). \\ \cline{2-3}
& xxhdpi & Resources for extra-extra-high-density (xxhdpi) screens (~480dpi). \\ \cline{2-3}
& xxxhdpi & Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above. \\ \cline{2-3}
& nodpi & Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density. \\ \cline{2-3}
& tvdpi & Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a ``primary'' density group. It is mostly intended for televisions and most apps shouldn't need it-providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi. \\ \hline
Orientation & land & Resources for screens in the landscape orientation (wide aspect ratio). \\ \hline
& port & Resources for screens in the portrait orientation (tall aspect ratio). \\ \hline
\multirow{2}{*}{Aspect Ratio} & long & Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration. \\ \cline{2-3}
& notlong & Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration. \\ \hline
\caption{Resolution suffixes}
\label{table:ressuffixes}
\end{longtable}
\end{document}
答案2
由于您希望保留设置表格材料宽度的能力并拥有三个等宽的列,您可以按如下方式进行:(i)加载longtable
,,tabularx
和 ltxtable
包,(ii)将longtable
材料(将包含tabularx
包定义的列类型)放在单独的文件中,以及(iii)\LTXtable{\textwidth}{<name of file containing the long table>}
在文档主体中使用该命令来插入长表。
另外,由于列很窄,我还建议您加载包ragged2e
并定义一种新的列类型,例如,Y
以不规则的方式排版其内容,以避免单词间出现较大的间隙。我还建议,由于表格将跨越多页,因此应将表格的标题移至表格的开头而不是结尾。
在下面的代码中,我使用filecontents
包来使代码自成一体。实际上,您只需将环境材料filecontents*
单独放在一个文件中即可。
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{longtable,tabularx,ltxtable,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\usepackage{filecontents}
\begin{filecontents*}{mylongtable.tex}
\begin{longtable}{|l|l|Y} %% seems better than "{|Y|Y|Y|}"
\caption{Resolution suffixes} \label{table:ressuffixes}\\
\hline
\textbf{Screen Charateristics} & \textbf{Qualifier} & \textbf{Description} \\
\hline
\endfirsthead
\multicolumn{3}{l}{Table \ref{table:ressuffixes}: Resolution suffixes, continued}\\[1ex]
\hline
\textbf{Screen Charateristics} & \textbf{Qualifier} & \textbf{Description} \\
\hline
\endhead
\hline
\endfoot
Size & small & Resources for small size screens.
\\ \cline{2-3}
& normal & Resources for normal size screens. (This is the baseline size.)
\\ \cline{2-3}
& large & Resources for large size screens.
\\ \cline{2-3}
& xlarge & Resources for extra-large size screens.
\\ \hline
Density & ldpi & Resources for low-density (ldpi) screens (~120dpi).
\\ \cline{2-3}
& mdpi & Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
\\ \cline{2-3}
& hdpi & Resources for high-density (hdpi) screens (~240dpi).
\\ \cline{2-3}
& xhdpi & Resources for extra-high-density (xhdpi) screens (~320dpi).
\\ \cline{2-3}
& xxhdpi & Resources for extra-extra-high-density (xxhdpi) screens (~480dpi).
\\ \cline{2-3}
& xxxhdpi & Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above.
\\ \cline{2-3}
& nodpi & Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
\\ \cline{2-3}
& tvdpi & Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a ``primary'' density group. It is mostly intended for televisions and most apps shouldn't need it-providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi. \\ \hline
Orientation & land & Resources for screens in the landscape orientation (wide aspect ratio).
\\ %% \cline{2-3}
& port & Resources for screens in the portrait orientation (tall aspect ratio).
\\ \hline
Aspect Ratio & long & Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration.
\\ \cline{2-3}
& notlong & Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration.
\end{longtable}
\end{filecontents*}
\begin{document}
\LTXtable{\textwidth}{mylongtable.tex}
\end{document}
答案3
一个仅使用一X
列以及booktabs
和makecell
包来改善表格外观的命题。我还加载了siunitx
包,定义了一个新单位,\dotperinch
并派生了dpi
一个带有一个参数的命令,即每英寸的点数:
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e, textcomp}
\usepackage{amsmath, nccmath}
\usepackage{array, tabularx, ltablex, caption}
\usepackage{multirow}
\usepackage{makecell, booktabs}
\setlength\aboverulesep{1.ex}
\setlength\belowrulesep{1.ex}
\renewcommand\theadfont{\bfseries\upshape}
\renewcommand\theadalign{lc}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\renewcommand{\tabularxcolumn}[1]{>{\RaggedRight\arraybackslash}m{#1}}
\newcommand\about{\ensuremath{\medmath{ ∼ \,}}}
\usepackage{siunitx}
\DeclareSIUnit{\dotperinch}{dpi}
\newcommand\dpi[1]{\SI{#1}{\dotperinch}}
\title{Your Paper}
\author{You}
\date{\today}
\begin{document}
\maketitle
{\setlength\defaultaddspace{2ex}
\begin{tabularx}{\linewidth}{>{\itshape}lr@{\qquad}X}
\toprule
\thead{Screen\\Characteristics} & \thead{Qualifier} & \thead{Description} \\
\midrule
Size & small & Resources for small size screens. \\
\addlinespace
& normal & Resources for normal size screens. (This is the baseline size.) \\
\addlinespace
& large & Resources for large size screens. \\
\addlinespace
& xlarge & Resources for extra-large size screens. \\
\cmidrule(lr){1-3}
Density & ldpi & Resources for low-density (ldpi) screens (\about\dpi{120}). \\
\addlinespace
& mdpi & Resources for medium-density (mdpi) screens (\about\dpi{160}). (This is the baseline density.) \\
\addlinespace
& hdpi & Resources for high-density (hdpi) screens (\about\dpi{240}). \\
\addlinespace
& xhdpi & Resources for extra-high-density (xhdpi) screens (\about\dpi{320}). \\
\addlinespace
& xxhdpi & Resources for extra-extra-high-density (xxhdpi) screens (\about\dpi{480}). \\
\addlinespace
& xxxhdpi & Resources for extra-extra-extra-high-density (xxxhdpi) uses (\about\dpi{640}). Use this for the launcher icon only, see note above. \\
\addlinespace
& nodpi & Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density. \\
\addlinespace
& tvdpi & Resources for screens somewhere between mdpi and hdpi; approximately \dpi{213}. This is not considered a ``primary'' density group. It is mostly intended for televisions and most apps shouldn't need it-providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100\,px $ × $ 100\,px image for mdpi screens should be 133\,px $ × $ 133\,px for tvdpi. \\
\cmidrule(lr){1-3}
Orientation & land & Resources for screens in the landscape orientation (wide aspect ratio). \\
\addlinespace
& port & Resources for screens in the portrait orientation (tall aspect ratio). \\
\cmidrule(lr){1-3}
Aspect Ratio & long & Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration. \\
\addlinespace
& notlong & Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration. \\ \bottomrule
\end{tabularx}
\captionof{table}{Resolution suffixes}
\label{table:ressuffixes}}
\end{document}