下图是我正在处理的问题:
我想让表格适合文本中的图像,但我不喜欢 \includegraphics 产生的结果。因此,我猜最好的解决方案是复制表格本身。由于表格很大,如果将其水平放置(假设可以这样做),结果也不会很好。垂直放置会更好吗?
至于重现表格的代码,我想它可能类似于
\documentclass{book}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\usepackage{multirow}
\usepackage{booktabs} % horizontal lines, such as \toprule, \midrule and \bottomrule
\usepackage{tabularx} % tabularx environment
\usepackage{siunitx} % S type columns to improve alignment of numbers
\usepackage{threeparttable} % tablenotes environment and \tnote commend
\usepackage{makecell} % \thead command for column headers with manual line breaks
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\begin{document}
\begin{table}
\begin{threeparttable}
\caption{Participant Characteristics}
\label{tab:key}
\begin{tabularx}{\linewidth}{@{}>{\raggedright\arraybackslash\hangindent=6pt}X r@{\;}l r@{\;}l S[table-format=1.3]@{}}
\toprule
\thead[bl]{Variables}
& \multicolumn{2}{c}{\thead[b]{More \\experienced \\ investors}}
& \multicolumn{2}{c}{\thead[b]{Less \\experienced \\ investors}}
& {\thead[b]{P-Value\tnote{*}}}\\
\midrule
Percentage who had previously invested in the stock market
& \multicolumn{2}{c}{78.50\%} & \multicolumn{2}{c}{36.78\%} & .001 \\
Years of business work experience
& 6.35 & (6.00) & 1.28 & (2.14) & .001 \\
Age
& 30.46 & (5.83) & 20.11 & (2.67) & .001 \\
Number of courses taken that discussed investing in mutual funds or the stock market
& 1.58 & (1.70) & .95 & (1.16) & .001 \\ Familiarity with mutual funds (1 = not at all familiar, 7 = very familiar)
& 4.59 & (1.61) & 3.63 & (4.96) & .011 \\ Importance in investing in mutual funds or the stock market (1 = not at all important, 7 = very important)
& 5.61 & (1.39) & 5.24 & (1.31) & .016 \\ Peers' views of investing in mutual funds or the stock market (1 = not at all desirable, 7 = very desirable) & 5.14 & (1.26) & 4.64 & (1.71) & .009 \\
\bottomrule
\end{tabularx}
\begin{tablenotes}[flushleft]
\small
\item[*] All tests are t-tests (one-tailed) except for the percentage investing, which is a chi-square test.
\end{tablenotes}
\end{threeparttable} \end{table} \end{document}
当然需要适当修改。我该如何修改上述代码才能得到我需要的六列,而不是它生成的四列(举例来说)?
我的方法(非常天真,因为我至少可以说还是个初学者;我只是修改了一个我认为可行的模板):
\documentclass{book}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\usepackage{multirow}
\usepackage{booktabs} % horizontal lines, such as \toprule, \midrule and \bottomrule
\usepackage{tabularx} % tabularx environment
\usepackage{siunitx} % S type columns to improve alignment of numbers
\usepackage{threeparttable} % tablenotes environment and \tnote commend
\usepackage{makecell} % \thead command for column headers with manual line breaks
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\begin{document}
\begin{table}
\tiny
\begin{tabular}{lccccc}
\toprule
Panel A: Percentage of Participants Willing to Invest in Mutual Funds\\
& Small Set Condition2 & Large Set Condition2 & Difference & Chi-Square & P-Value \\
\midrule
forza & $F$ & newton \\
energia & $E$ & joule \\
tensione & $V$ & volt \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
欢迎任何建议。
答案1
也许你会喜欢它:
(红线表示文本边框)
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
%\usepackage{graphicx}
%\graphicspath{ {./images/} }
\usepackage{ragged2e}
\usepackage{booktabs, % horizontal lines, such as \toprule, \midrule and \bottomrule
makecell, % \thead command for column headers with manual line breaks
multirow, % multirowcell
tabularx, % tabularx environment
threeparttable} % tablenotes environment and \tnote commend
\newcolumntype{L}{>{\RaggedRight}X}
\renewcommand\theadgape{}
\renewcommand\TPTtagStyle{\bfseries}
\usepackage{siunitx} % S type columns to improve alignment of numbers
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}
\sisetup{table-align-text-after=false}
\setlength\tabcolsep{3pt}
\small
\begin{threeparttable}
\caption{Participant Characteristics\tnote{1}}
\begin{tabularx}{\linewidth}{@{} L
S[table-format= 2.2{\%}]
S[table-format= 2.2{\%}]
S[table-format=-2.2{\%}]
S[table-format= 1.2]
S[table-format= 1.3]
@{}}
\toprule
\multicolumn{6}{l}{Panel A: Percentage of Participants Willing to Invest in Mutual Funds}\\
\midrule
& {\thead{Small Set\\ Condition 2}}
& {\thead{Small Set\\ Condition 2}}
& {\thead{Difference}}
& {\thead{Chi-Square}}
& {\thead{P-Value}} \\
\midrule
Less experienced investors/ no categories\tnote{3} $(b=61)$
& 93.1 \%
& 71.9 \%
& 21.2 \%
& 4.64 \%
& 0.031 \\
Moderate experienced investors/ no categories $(n=113)$
& 86.1 \,\%
& 71.9 \,\%
& 7.4 \,\%
& 1.06 \,\%
& 0.303 \\
More experienced investors/ no categories $(b=93)$
& 66.7 \,\%
& 78.6 \,\%
& -14.6 \,\%
& 2.28 \,\%
& 0.108 \\
\midrule
... \\
\bottomrule
\end{tabularx}
\begin{tablenotes}[flushleft,online]\footnotesize
\item[1] After review the investment fund choices, participant were asked whether or not they wanted to invest in one or more these mutual funds at the present time.
\item[2] Participants in the small (large) set condition were present with 5 (50) mutual funds from 5 categories: aggressive growth funds, growth and income stock funds, growth and income stock, and bond funds, and bond funds.
\item[3] Participants in the No Categories (Categories) condition received the mutual funds without (with) risk categories labels.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案2
我建议采用一种尝试减少重复的替代方法:
\documentclass{book}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\usepackage{multirow}
\usepackage{booktabs} % horizontal lines, such as \toprule, \midrule and \bottomrule
\usepackage{tabularx} % tabularx environment
\usepackage{siunitx} % S type columns to improve alignment of numbers
\usepackage{threeparttable} % tablenotes environment and \tnote commend
\usepackage{makecell} % \thead command for column headers with manual line breaks
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{subcaption}
\begin{document}
\begin{table}
\caption[your caption text]{your caption text\textsuperscript{1}}
\begin{threeparttable}
\begin{subtable}{\linewidth}
\caption{Percentage of Participants Willing to Invest in Mutual Funds}
\begin{tabularx}{\linewidth}{>{\raggedright\arraybackslash\hangindent=6pt}X
*{3}{S[table-format=-2.1, table-space-text-post={\%}]}
*{2}{S[table-format=1.3]}}
\toprule
& {\thead{Small Set\\ Condition\tnote{2}}} & {\thead{Large Set\\ Condition}} & {\thead{Difference}} & {\thead{Chi-Square}} & {\thead{P-Value}} \\
\midrule
some lengthy text in the first column\tnote{3} & 11.1\% & 11.1\% & 11.1\% & 1.11 & .111\\
some lengthy text in the first column & 11.1\% & 11.1\% & 11.1\% & 1.11 & .111\\
some lengthy text in the first column & 11.1\% & 11.1\% & 11.1\% & 1.11 & .111\\
\bottomrule
\end{tabularx}
\end{subtable}
\bigskip
\begin{subtable}{\linewidth}
\caption{second cubcaption}
\begin{tabularx}{\linewidth}{>{\raggedright\arraybackslash\hangindent=6pt}X *{2}{S[table-format=1.2]S[table-format=1.3]}}
\toprule
& \multicolumn{2}{c}{\thead{Small Set Conditions}} & \multicolumn{2}{c}{\thead{Large Set Conditions}} \\
\cmidrule(r){2-3} \cmidrule(l){4-5}
& {\thead{Chi-Square}} & {\thead{P-Value}} & {\thead{Chi-Square}} & {\thead{P-Value}} \\
\midrule
some lengthy text in the first column & 1.11 & .111 & 1.11 & .111\\
some lengthy text in the first column & 1.11 & .111 & 1.11 & .111\\
\bottomrule
\end{tabularx}
\end{subtable}
\begin{tablenotes} \footnotesize
\item[1] some table note text
\item[2] another a lot longer table note text which needs a line break another a lot longer table note text which needs a line break
\item[3] some table note text
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}