带有合并单元格的 tabularx 超出边界

带有合并单元格的 tabularx 超出边界

一旦我合并单元格,我的表格就会超出边界。

如何让合并单元格中的文本换行?

我的代码

    \documentclass[a4paper]{article}
\usepackage{booktabs,tabularx,multirow}

\begin{document}
    
    \begin{table}[]
        \centering
        \begin{tabularx}{\textwidth}{@{} p{0.12\textwidth}p{0.28\textwidth}p{0.28\textwidth}p{0.28\textwidth} @{}}
            \toprule
            &
            Mitigation strategy &
            \multicolumn{1}{l|}{Adaptation strategy} &
            \\ \midrule
            Approach &
            Actions taken to reduce   emissions that cause climate change &
            \multicolumn{2}{l|}{Adaptations made to operations   to manage the impact of climate change} \\ \midrule
            Focus &
            Addressing underlying cause of   climate change &
            \multicolumn{2}{l|}{Managing the risks and   vulnerabilities due to exposure to climate change} \\ \midrule
            \begin{tabular}[c]{@{}l@{}}Sub--\\ strategies\end{tabular} &
            N/A &
            \multicolumn{1}{l|}{Soft adaptation: Refining existing processes and operations; incremental approach} &
            Hard adaptation: Investing in new technology, infrastructure, and (re)location; transformational approach \\ \midrule
            \begin{tabular}[c]{@{}l@{}}Time\\ horizon\end{tabular} &
            Long-term &
            \multicolumn{1}{l|}{Short-term} &
            Medium-term \\ \midrule
            Scale &
            Global &
            \multicolumn{2}{l|}{More local} \\ \midrule
            \begin{tabular}[c]{@{}l@{}}Financial \\ investment\end{tabular} &
            Medium-high &
            \multicolumn{1}{l|}{Low-medium} &
            Medium-high \\ \midrule
            \begin{tabular}[c]{@{}l@{}}Aviation\\ industry\\ examples\end{tabular} &
            Galápagos Ecological Airport designed to run completely on renewable energies (65\% from wind, 35\% from solar), and using 80\% recycled materials in its construction and re-use of wastewater in its system (estimated costs \$40 million) &
            \multicolumn{1}{l|}{Changi Airport resurfacing Runway 1 with stronger and more durable asphalt with higher temperature resistance due to climate change (estimated cost \$50 million)} &
            Plans to build a new 10-mile long sea wall at San Francisco International Airport to guard against 3 feet of sea level rise plus 2 more feet for storms/waves (estimated cost \$587 million) \\ \bottomrule
        \end{tabularx}
    \end{table}
\end{document}

输出

在此处输入图片描述

原始表 在此处输入图片描述

答案1

像这样:

在此处输入图片描述

如果使用tabularray包、ragged2e用于格式化单元格中的文本的包以及booktabs用于siunitx表格规则和一致写入数量百分比的包,表格代码会更加简单和简洁:

\documentclass[a4paper]{article}
\usepackage{ragged2e}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{table}[ht]
        \centering
\begin{tblr}{colsep=3pt,
             colspec = {X[l, m] | X[1.5, cmd=\RaggedRight]  
                                | X[1.5, cmd=\RaggedRight] 
                                | X[1.5, cmd=\RaggedRight]  @{}},
             hspan = minimal}
        \toprule
    &   Mitigation strategy   
        &   \SetCell[c=2]{c}    Adaptation strategy  
            &       \\ 
        \midrule
Approach    
    & Actions taken to reduce  emissions that cause climate change 
        &   \SetCell[c=2]{j}    Adaptations made to operations to manage the impact of climate change   \\ \midrule
Focus 
    & Addressing underlying cause of   climate change 
        &   \SetCell[c=2]{j}    Managing the risks and vulnerabilities due to exposure to climate change \\ \midrule
Sub-strategies
    & N/A 
        &   Soft adaptation: Refining existing processes and operations; incremental approach
            &   Hard adaptation: Investing in new technology, infrastructure, and (re)location; transformational approach                                                                   \\
        \midrule
Time horizon
    &   Long-term 
        &   {Short-term} 
            &   Medium-term                                                                             \\ 
        \midrule
Scale 
    &   Global
        &   \SetCell[c=2]{j}    More local                                                              \\ 
        \midrule
Financial investment
    &   Medium-high 
        &   Low-medium
            &   Medium-high                                                                             \\
    \midrule
Aviation industry examples
    &   Galápagos Ecological Airport designed to run completely on renewable energies (\qty{65}{\%} from wind, \qty{35}{\%} from solar), and using \qty{80}{\%} recycled materials in its construction and re-use of waste water in its system (estimated costs \$40 million) 
        &   Changi Airport resurfacing Runway 1 with stronger and more durable asphalt with higher temperature resistance due to climate change (estimated cost \$50 million) 
            &   Plans to build a new 10-mile long sea wall at San Francisco International Airport to guard against 3 feet of sea level rise plus 2 more feet for storms/waves (estimated cost \$587 million \\ 
        \bottomrule
\end{tblr}
    \end{table}
\end{document}

tabularray编写多列单元格的语法略有不同:SetCell[c=<num. of columns>]{j}。有关详细信息,请参阅包文档。

编辑:
更正了最后两列的列标题。

答案2

只是为了完整性(因为 OP 使用了一个tabularx环境),这里有一个tabularx基于 的解决方案。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{P}{p{\dimexpr0.51\textwidth+2\tabcolsep\relax}@{}}
  % 0.51=2*0.255
\begin{document}

\begin{table}[tbp]
\setlength\tabcolsep{3pt} % default: 6pt
\begin{tabularx}{\textwidth}{@{} 
     >{\raggedright}X 
     *{3}{>{\RaggedRight}p{0.255\textwidth}} 
     @{}}
   \toprule
   &
   Mitigation strategy &
   \multicolumn{2}{c@{}}{Adaptation strategy} \\ 
   \midrule
   Approach &
   Actions taken to reduce emissions that cause climate change &
   \multicolumn{2}{P}{Adaptations made to operations to manage the impact of climate change} \\ 
   \midrule
   Focus &
   Address underlying cause of climate change &
   \multicolumn{2}{P}{Manage the risks and vulnerabilities due to exposure to climate change} \\ 
   
   & & \multicolumn{2}{c@{}}{Adaptation Substrategies} \\
   \cmidrule(l){3-4}
   & &
   Soft adaptation: Refine existing processes and operations; incremental approach &
   Hard adaptation: Invest in new technology, infrastructure, and (re)location; transformational approach\\ 
   \midrule
   
   \addlinespace[3ex]
   Time horizon & Long-term & Short-term & Medium-term \\ 
   \midrule
   Scale & Global & More local \\ 
   \midrule
   Financial investment 
   & Medium--high & Low--medium & Medium--high \\ 
   \midrule
   Aviation industry examples &
   Galápagos Ecological Airport designed to run completely on renewable energies (65\% from wind, 35\% from solar), and using 80\% recycled materials in its construction and re-use of wastewater in its system. 
   
   Estimated cost: \$40~million &
   Changi Airport resurfacing Runway~1 with stronger and more durable asphalt with higher temperature resistance due to climate change. 
   
   Estimated cost: \$50~million &
   Plans to build a new 10-mile long sea wall at San Francisco International Airport to guard against 3~feet of sea level rise plus 2 more feet for storms\slash waves. 
   
   Estimated cost: \$587 million \\ 
   \bottomrule
\end{tabularx}
\end{table}
\end{document}

相关内容