我正在构建一个大表格,并希望将每个“单元格”中的文本对齐到左上角。这对第 3 列中的文本不起作用。我需要如何更改代码才能使其对齐到第 3 列的左上角?
\begin{table}
\centering
\resizebox{\linewidth}{!}{%
\begin{tabular}{|l|l|>\justify m{7cm}l|l|l|}
\hline
Abbreviation & Name & Variable Description & Frequency & Source \\
\hline
\vcell{\textit{YS}} & \vcell{Yield Spread} & \vcell{Yield-to-maturity of corporate bond minus yield of maturity
matched Treasury} & \vcell{Monthly} & \vcell{TRACE, Liu and Wu (2021)} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{SP500}} & \vcell{SP 500 return} & \vcell{Return of the SP 500 composite index} & \vcell{Monthly} & \vcell{CRSP} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{VIX}} & \vcell{VIX} & \vcell{CBOE volatility index} & \vcell{Monthly} & \vcell{McCracken
and Ng (2016)} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{TS}} & \vcell{Term Spread} & \vcell{10-Year Treasury Rate minus 3-Month Treasury Bill} & \vcell{Monthly} & \vcell{McCracken
and Ng (2016)} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{TR}} & \vcell{Treasury Rate} & \vcell{10-Year Treasury Rate} & \vcell{Monthly} & \vcell{McCracken
and Ng (2016)} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{IVOL}} & \vcell{Interest rate volatility} & \vcell{Standard deviation of daily one-month constant maturity
Treasury over a 12-month period prior to bond transaction date} & \vcell{Monthly} & \vcell{CRSP} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{DRS}} & \vcell{Default risk spread} & \vcell{Moody's Seasoned Aaa Corproate Bond Yield minus Moody's
Seasoned Baa Corporate Bond Yield} & \vcell{Monthly} & \vcell{McCracken
and Ng (2016)} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{MB}} & \vcell{Market-to-book ratio} & \vcell{Market value of equity divided by book value of equity} & \vcell{Quarterly} & \vcell{Compustat} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{EVOL}} & \vcell{Equity volatility} & \vcell{Standard deviation of daily excess returns over the CRSP
value-weighted index over a 12-month period prior to bond transaction date} & \vcell{Monthly} & \vcell{CRSP} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{ER}} & \vcell{Equity return} & \vcell{REIT holding period equity return} & \vcell{Monthly} & \vcell{CRSP} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{HY}} & \vcell{High-Yield} & \vcell{1 if high-yield bond. 0 if investment-grade bond} & \vcell{Nominal} & \vcell{TRACE-Morningstar Website} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{CALL}} & \vcell{Callable~} & \vcell{1 if callable. 0 if not} & \vcell{-} & \vcell{TRACE-Morningstar Website} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{TTM}} & \vcell{Time to maturity} & \vcell{Difference in months between maturity date and transaction
date} & \vcell{Monthly} & \vcell{TRACE-Morningstar Website} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{CR}} & \vcell{Coupon rate} & \vcell{Coupon rate on bond in percent} & \vcell{-} & \vcell{TRACE-Morningstar Website} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{LEV}} & \vcell{Leverage} & \vcell{Sum of long-term debt and short-term debt divbided by book
value of equity} & \vcell{Quarterly} & \vcell{Compustat} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{SIZE}} & \vcell{REIT Size} & \vcell{Natural logarithm of total assets} & \vcell{Quarterly} & \vcell{Compustat} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{ROA}} & \vcell{Return on Assets} & \vcell{Net income divided by total assets} & \vcell{Quarterly} & \vcell{Compustat} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{FFO}} & \vcell{Funds from operations} & \vcell{Funds from operations} & \vcell{Quarterly} & \vcell{Compustat} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{\textit{TYPE}} & \vcell{Type of REIT} & \vcell{16 NAREIT defined types of REIT~} & \vcell{-} & \vcell{NAREIT} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\vcell{RER} & \vcell{NPI return} & \vcell{National Property Index Total Return dependent on REIT type} & \vcell{Quarterly} & \vcell{NCREIF} \\[-\rowheight]
\printcelltop & \printcelltop & \printcelltop & \printcelltop & \printcelltop \\
\hline
\end{tabular}
}
\end{table}
答案1
尽可能减少冗长和重复的内容。使用可变大小的列。切勿缩放表格。
我不确定是什么\vcell
,\printcelltop
但它们可以被删除,从而大大简化输入。
\documentclass[a4paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\footnotesize
\begin{tabularx}{\textwidth}{
|
l
|
>{\raggedright\hsize=0.5\hsize}X
|
>{\raggedright\hsize=1.8\hsize}X
r
|
>{\raggedright\arraybackslash\hsize=0.7\hsize}X
|
}
\hline
Abbr. & Name & Variable Description & \makebox[1em][r]{Freq.} & Source \\
\hline
\textit{YS} & Yield Spread
& Yield-to-maturity of corporate bond minus yield of maturity
matched Treasury
& M & TRACE, Liu and Wu (2021) \\
\hline
\textit{SP500} & SP 500 return
& Return of the SP 500 composite index
& M & CRSP \\
\hline
\textit{VIX} & VIX
& CBOE volatility index
& M & McCracken and Ng (2016) \\
\hline
\textit{TS} & Term Spread
& 10-Year Treasury Rate minus 3-Month Treasury Bill
& M & McCracken and Ng (2016) \\
\hline
\textit{TR} & Treasury Rate
& 10-Year Treasury Rate & M
& McCracken and Ng (2016) \\
\hline
\textit{IVOL} & Interest rate volatility
& Standard deviation of daily one-month constant maturity
Treasury over a 12-month period prior to bond transaction date
& M & CRSP \\
\hline
\textit{DRS} & Default risk spread
& Moody's Seasoned Aaa Corproate Bond Yield minus Moody's
Seasoned Baa Corporate Bond Yield
& M & McCracken and Ng (2016) \\
\hline
\textit{MB} & Market-to-book ratio
& Market value of equity divided by book value of equity
& Q & Compustat \\
\hline
\textit{EVOL} & Equity volatility
& Standard deviation of daily excess returns over the CRSP
value-weighted index over a 12-month period prior to bond transaction date
& M & CRSP \\
\hline
\textit{ER} & Equity return
& REIT holding period equity return
& M & CRSP \\
\hline
\textit{HY} & High-Yield &
1 if high-yield bond. 0 if investment-grade bond
& N & TRACE-MW \\
\hline
\textit{CALL} & Callable
& 1 if callable. 0 if not
& -- & TRACE-MW \\
\hline
\textit{TTM} & Time to maturity
& Difference in months between maturity date and transaction date
& M & TRACE-MW \\
\hline
\textit{CR} & Coupon rate
& Coupon rate on bond in percent
& -- & TRACE-MW \\
\hline
\textit{LEV} & Leverage
& Sum of long-term debt and short-term debt divided by book value of equity
& Q & Compustat \\
\hline
\textit{SIZE} & REIT Size
& Natural logarithm of total assets
& Q & Compustat \\
\hline
\textit{ROA} & Return on Assets
& Net income divided by total assets
& Q & Compustat \\
\hline
\textit{FFO} & Funds from operations
& Funds from operations
& Q & Compustat \\
\hline
\textit{TYPE} & Type of REIT
& 16 NAREIT defined types of REIT
& -- & NAREIT \\
\hline
\textit{RER} & NPI return
& National Property Index Total Return dependent on REIT type
& Q & NCREIF \\
\hline
\multicolumn{5}{@{}l}{M: Monthly; N: Nominal; Q: Quarterly.\qquad MW: Morningstar Website}
\end{tabularx}
\end{table}
\end{document}
但我会考虑采用如下不同的格式。
\documentclass[a4paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{itemize}
\item Yield Spread (YS) \\
Yield-to-maturity of corporate bond minus yield of maturity matched Treasury.
F:~Monthly, S:~TRACE, Liu and Wu (2021)
\item SP 500 return (SP500) \\
Return of the SP 500 composite index.
F:~Monthly, S:~CRSP
\item VIX \\
CBOE volatility index.
F:~Monthly, S:~McCracken and Ng (2016)
\item Term Spread (TS) \\
10-Year Treasury Rate minus 3-Month Treasury Bill.
F:~Monthly, S:~McCracken and Ng (2016)
\end{itemize}
\caption{Some caption}
\end{table}
table
这可能不是一个 ,而是一个\section
。 \end{document}
答案2
我只是猜测...你可能正在寻找这样的东西:
抱歉,但您的代码片段没有任何帮助(关于表格的格式)。删除所有未定义的命令后,使用tabularray
package for table,可能的解决方案可能是:
\documentclass{article}
\usepackage[margin=20mm]{geometry}
\usepackage{tabularray}
\begin{document}
\begin{table}
\small
\begin{tblr}{hlines, vlines,
colspec = {Q[l,font=\itshape] l X[j] l l},
row{1} = {font=\bfseries, c}
}
Abbr. & Name & Variable Description & Frequency & Source \\
YS & Yield Spread
& Yield-to-maturity of corporate bond minus yield of maturity
matched Treasury
& Monthly & TRACE, Liu and Wu (2021) \\
SP500 & SP 500 return
& Return of the SP 500 composite index
& Monthly & CRSP \\
VIX & VIX & CBOE volatility index & Monthly & McCracken and Ng (2016) \\
TS & Term Spread
& 10-Year Treasury Rate minus 3-Month Treasury Bill
& Monthly & McCracken and Ng (2016) \\
TR & Treasury Rate
& 10-Year Treasury Rate & Monthly & McCracken and Ng (2016) \\
IVOL & Interest rate volatility
& Standard deviation of daily one-month constant maturity Treasury over a 12-month period prior to bond transaction date
& Monthly & CRSP \\
DRS & Default risk spread
& Moody's Seasoned Aaa Corproate Bond Yield minus Moody's Seasoned Baa Corporate Bond Yield
& Monthly & McCracken and Ng (2016) \\
MB & Market-to-book ratio
& Market value of equity divided by book value of equity
& Quarterly & Compustat \\
EVOL & Equity volatility
& Standard deviation of daily excess returns over the CRSP value-weighted index over a 12-month period prior to bond transaction date
& Monthly & CRSP \\
ER & Equity return
& REIT holding period equity return
& Monthly & CRSP \\
HY & High-Yield
& 1 if high-yield bond. 0 if investment-grade bond
& Nominal & TRACE-Morningstar Website \\
CALL & Callable
& 1 if callable. 0 if not
& -- & TRACE-Morningstar Website \\
TTM & Time to maturity
& Difference in months between maturity date and transaction date
& Monthly & TRACE-Morningstar Website \\
CR & Coupon rate
& Coupon rate on bond in percent
& -- & TRACE-Morningstar Website \\
LEV & Leverage
& Sum of long-term debt and short-term debt divbided by book value of equity
& Quarterly & Compustat \\
SIZE & REIT Size
& Natural logarithm of total assets
& Quarterly & Compustat \\
ROA & Return on Assets
& Net income divided by total assets
& Quarterly & Compustat \\
FFO & Funds from operations
& Funds from operations & Quarterly & Compustat \\
TYPE & Type of REIT
& 16 NAREIT defined types of REIT~
& -- & NAREIT \\
RER & NPI return
& National Property Index Total Return dependent on REIT type
& Quarterly & NCREIF \\
\end{tblr}
\end{table}
\end{document}
当然,你的表格也可以用其他方式编写。例如,使用tabularx
包。使用它,表格序言是:
\begin{tabularx}{\linewidth}{|>{\itshape}l | X | l | l |}
您需要\hline
在每一行之后和表体的开头插入。结果将与上面显示的类似(但不相同)。
答案3
这里有一个解决方案,它 (a) 采用一个xltabular
环境,以便在需要时允许分页符,并且 (b) 允许在表格的 5 列中的 3 列中自动换行,并将第 3 列的宽度设置为第 2 列的三倍。这样,adjustbox
就可以完全避免混乱,并且可用的字体大小是\normalsize
- 无需诉诸\small
、\footnotesize
或任何甚至更小的相对字体大小。
在以下示例中,整个表格恰好适合一页。不过,代码足够灵活,如果文档边距比下面假设的要宽,则可以在表格材料中自动分页。不需要神秘的\justify
、\vcell
和\printcelltop
宏。代码还取消了所有垂直线和大多数水平线,以便为表格提供开放且吸引人的“外观”。
\documentclass{article} % or some other suitable document class
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters as needed
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{xltabular} % for 'xltabular' environment and X col. type
%% define two subsidiary column types
\newcolumntype{L}[1]{%
>{\raggedright\arraybackslash\hsize=#1\hsize\hspace{0pt}}X}
\newcolumntype{P}[1]{%
>{\raggedright\arraybackslash\hspace{0pt}}p{#1}}
\newlength\mylen
\settowidth\mylen{and Wu (2021)} % target width of final column
\begin{document}
\begingroup % localize scope of next instruction
\setlength\extrarowheight{3pt}
\begin{xltabular}{\textwidth}{@{} >{\itshape}l L{0.5} L{1.5} c P{\mylen} @{}}
%% headers and footers
\toprule
\textup{Abbrev.} & Name & Variable Description & Freq. & Source \\
\midrule
\endfirsthead
\multicolumn{5}{@{}l}{\small (\textit{continued from preceding page})}\\
\addlinespace
\toprule
\textup{Abbrev.} & Name & Variable Description & Freq. & Source \\
\midrule
\endhead
\midrule
\multicolumn{5}{r@{}}{\footnotesize \textit{continued on next page})}\\
\endfoot
\bottomrule
\endlastfoot
%% body of table
YS & Yield Spread & Yield-to-maturity of corporate bond minus yield of maturity matched Treasury & M & TRACE, Liu and Wu (2021) \\
SP500 & S\&P\,500 return & Return of the S\&P\,500 composite index & M & CRSP \\
VIX & VIX & CBOE volatility index & M & McCracken and Ng (2016) \\
TS & Term Spread & 10-year Treasury note rate minus 3-month Treasury bill rate & M & McCracken and Ng (2016) \\
TR & Treasury Rate & 10-year Treasury rate & M & McCracken and Ng (2016) \\
IVOL & Interest rate volatility & Standard deviation of daily one-month constant maturity Treasury over a 12-month period prior to bond transaction date & M & CRSP \\
DRS & Default risk spread & Moody's Seasoned Aaa corproate bond yield minus Moody's Seasoned Baa corporate bond yield & M & McCracken and Ng (2016) \\
MB & Market-to-book ratio & Market value of equity divided by book value of equity & Q & Compustat \\
EVOL & Equity volatility & Standard deviation of daily excess returns over the CRSP value-weighted index over a 12-month period prior to bond transaction date & M & CRSP \\
ER & Equity return & REIT holding period equity return & M & CRSP \\
HY & High-Yield & Dummy variable: 1 if high-yield bond, 0 if investment-grade bond & Nom. & TRACE-Morningstar Website \\
CALL & Callable & Dummy variable: 1 if callable, 0 if not & -- & TRACE-Morningstar Website \\
TTM & Time to maturity & Difference in months between maturity date and transaction date & M & TRACE-Morningstar Website \\
CR & Coupon rate & Coupon rate on bond in percent & -- & TRACE-Morningstar Website \\
LEV & Leverage & Sum of long-term debt and short-term debt divbided by book value of equity & Q & Compustat \\
SIZE & REIT Size & Natural logarithm of total assets & Q & Compustat \\
ROA & Return on Assets & Net income divided by total assets & Q & Compustat \\
FFO & Funds from operations & Funds from operations & Q & Compustat \\
TYPE & Type of REIT & 16 NAREIT defined types of REIT & -- & NAREIT \\
RER & NPI return & National Property Index Total Return dependent on REIT type & Q & NCREIF \\
\end{xltabular}
\endgroup
\end{document}