重塑、拟合多列表格

重塑、拟合多列表格

您好,我有下面的代码,我想将其调整到适合页面,并根据搜索词的行将值居中。提前谢谢您。在此处输入图片描述

\documentclass[11pt,authoryear,sort&compress]{report}
\usepackage{booktabs,tabulary,array,tabularx}
\usepackage{geometry}
\newcolumntype{z}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
    \centering
    \footnotesize
    \begin{tabularx}{1\textwidth}
        {%l
            >{\raggedright\arraybackslash}p{4cm} 
            %>{\raggedright\arraybackslash}p{3cm} 
            c
            c
            %>{\raggedright\arraybackslash}X 
            c
            c
            c
            c
            c}
        \toprule  
        Search Words & Period & Search Technique & \multicolumn{2}{c}{Initial Search Results} & Final Sample &
        \multicolumn{2}{c}{Analysis Perform}\tabularnewline
        \cline{4-5} \cline{5-5} 
        &  &  & No. of articles & Total local citations &  &  & \tabularnewline
        (("determinants" or "discrimination") and ("finance" or "credit" or  "capital" or "financial services") and ("access")) & 5 & 5 & 5 & 5 & 5 & 5 & 5\tabularnewline
        & &\tabularnewline
        ("financial inclusion") & 5 & 5 & 5 & 5 & 5 & 5 & 5\tabularnewline
        \bottomrule%
    \end{tabularx}%
    \caption{caption.}
    \label{tab:final.sample.biblio} 
\end{table}

\end{document}

答案1

正如我之前的评论中提到的,tabularx没有任何X类型列的环境是没有意义的。第一步是用p类型列替换当前用于第一列的类型列X。由于此列现在变得太窄,我们可以在列标题内允许换行符。为此,我使用了包\thead中的命令makecell。为了避免第一列内出现大面积空白,我添加了>{\raggedright\arraybackslash}从两端对齐切换到右不等对齐。我还用您已经使用的包中的\cline命令替换了命令。我还稍微降低了值并将字体大小从增加到。为了使每个单元格的内容相对于第一列的内容垂直居中,我添加了 。最后,我无法理解的原因,并猜测最后两列缺少一些列标题,所以我添加了它们。\cmidrulebooktabs\tabcolsep\footnotesize\small\renewcommand\tabularxcolumn[1]{m{#1}}\cline{4-5} \cline{5-5}

在此处输入图片描述

\documentclass[11pt]{report}
\usepackage{booktabs,tabularx}
\usepackage{geometry}
\usepackage{makecell}
    
\begin{document}
\begin{table}
    \small
    \renewcommand\tabularxcolumn[1]{m{#1}}
    \renewcommand{\theadalign}{tc}
    \setlength{\tabcolsep}{4pt}
    \caption{caption.}
    \label{tab:final.sample.biblio} 
    \begin{tabularx}{1\textwidth}
        {@{}
            >{\raggedright\arraybackslash}X
            c
            c 
            c
            c
            c
            c
            c @{}}
        \toprule  
        \thead[l]{Search Words} & \thead{Period} & \smash{\thead{Search\\ Technique}} & \multicolumn{2}{c}{\thead{Initial Search Results}} &  \smash{\thead[t]{Final\\ Sample}} &
        \multicolumn{2}{c}{Analysis Perform}\tabularnewline
        \cmidrule(lr){4-5} \cmidrule(lr){7-8}
        &  &  & \thead{No. of\\ articles} & \thead{Total local\\ citations} &  &  \thead{text} & \thead{text} \tabularnewline
        \midrule
        (("determinants" or "discrimination") and ("finance" or "credit" or  "capital" or "financial services") and ("access")) & 5 & 5 & 5 & 5 & 5 & 5 & 5\tabularnewline
        & &\tabularnewline
        ("financial inclusion") & 5 & 5 & 5 & 5 & 5 & 5 & 5\tabularnewline
        \bottomrule%
    \end{tabularx}%
\end{table}

\end{document}

相关内容