我的表格对于我的页面来说太宽,如何使文本在特定的列上换行?

我的表格对于我的页面来说太宽,如何使文本在特定的列上换行?

下面是我的表格的代码(使用http://www.tablesgenerator.com/),遗憾的是,将表格参数更改为使用p设置宽度似乎不起作用。

\documentclass[11pt,a4paper]{report}
\begin{document}
% Please add the following required packages to your document preamble:
% \usepackage{booktabs}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}|ll|l|l|l|l|@{}}
\toprule
\multicolumn{1}{|r}{\textbf{Browser:}}     & Chrome        &                                 & \multicolumn{3}{c|}{\textit{\textbf{All T2 tests are ran following T1-02}}}                                                                                                                                                              \\ \midrule
\multicolumn{1}{|l|}{\textbf{Test number}} & \textbf{Page} & \textbf{Test description}       & \textbf{Steps}                                                                                       & \textbf{Expected outcome}                                                                                  & \textbf{Pass? (Y/N)} \\ \midrule
\multicolumn{1}{|l|}{T2-01}                & Itinerary     & Rename itinerary                & Click edit icon, to the right of the itinerary name, type 'mytinerary' and click the edit icon again & The name 'mytinerary' is now the displayed name for the itinerary                                          & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-02}                & Itinerary     & Rename itinerary                & Click edit icon, to the right of the itinerary name, type 'mytinerary' and press enter               & The name 'mytinerary' is now the displayed name for the itinerary                                          & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-03}                & Itinerary     & Reset itinerary name            & Repeat T2-02. Click the edit icon, delete all text in the field and press enter                      & The original location 'London, United Kingdom' is the displayed name for the itinerary                     & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-04}                & Itinerary     & Reset itinerary                 & Click the 'Restart' button                                                                           & Redirected to the landing page, there is an additional button with text "Revisit 'London, United Kingdom'" & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-05}                & Itinerary     & Reset and rejoin itinerary      & Click the 'Restart' button, then click the 'Revisit' button                                          & Redirected to the landing page and then brought back to the itinerary page                                 & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-06}                & Itinerary     & Access venue information        & Click the name of the first itinerary item                                                           & Pop-up menu activates and displays information for the venue.                                              & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-07}                & Itinerary     & Close venue information         & Repeat T2-06 and then click the 'x' icon                                                             & Pop-up menu closes and you are left on the itinerary page                                                  & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-08}                & Itinerary     & Close venue information         & Repeat T2-06 and press the escape key                                                                & Pop-up menu closes and you are left on the itinerary page                                                  & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-09}                & Itinerary     & Next venue                      & Click the right arrow for an itinerary item                                                          & Venue name should change                                                                                   & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-10}                & Itinerary     & Previous venue                  & Repeat T2-09 and then click the left arrow of the same itinerary item                                & Venue name should be unchanged                                                                             & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-11}                & Itinerary     & Open genre menu                 & Click the genre menu                                                                                 & Genre menu is displayed                                                                                    & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-12}                & Itinerary     & Close genre menu                & Repeat T2-12 and click close button                                                                  & Genre menu is not displayed                                                                                & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-13}                & Itinerary     & Close genre menu                & Repeat T2-12 and click the genre menu                                                                & Genre menu is not displayed                                                                                & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-14}                & Itinerary     & Add genre venue options         & Repeat T2-12 and click a glyph                                                                       & Genre menu displayed, clicked glyph has been highlighted and the venue has changed                         & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-15}                & Itinerary     & Pin item                        & Click the pin button for an itinerary item                                                           & Pin button is filled                                                                                       & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-16}                & Itinerary     & Unpin Item                      & Repeat T2-15 and then click the pin button again                                                     & Pin button is hollow                                                                                       & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-17}                & Itinerary     & Next venue for pinned item      & Repeat T2-15 and click an arrow button                                                               & No change in the itinerary item                                                                            & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-18}                & Itinerary     & Open genre menu for pinned item & Repeat T2-15 and click the genre menu                                                                & No change in the itinerary item                                                                            & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-19}                & Itinerary     & Drag itinerary item             & Drag the first itinerary item over the last itinerary item                                           & An orange bar should appear between the last two itinerary items                                           & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-20}                & Itinerary     & Drag and drop itinerary item    & Drag the last itinerary item over the first itinerary item and drop it                               & The itinerary item that was dragged should now be at the top of the itinerary                              & Y                    \\ \midrule
\multicolumn{1}{|l|}{T2-21}                & Itinerary     & Expose travel elements          & Pin all 5 itinerary items                                                                            & The travel elements should now be displayed underneath all but the last itinerary item                     & Y                    \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

我的文档中的表格如下所示:

表格如我的文档中所示

我正在使用我大学的论文模板,可以在这里找到背页

如何使第 3 至第 5 列单元格中的文本换行?

答案1

像这样?

在此处输入图片描述 我建议使用tabularx环境。由于您没有提供任何有关页面布局的信息,我选择margin=25mm使用包geometry。由于表格很大,我还建议使用较小的字体大小(\small`)。在下面的 MWE 中,我只考虑前十行:

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, tabularx}
\renewcommand\theadfont{\bfseries\small}
\newcolumntype{R}{>{\RaggedRight}X}

  \begin{document}
\begin{table}[ht]
    \small
    \setlength\tabcolsep{3pt}
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{@{} ll >{\hsize=0.6\hsize}R 
                                    >{\hsize=1.2\hsize}R 
                                    >{\hsize=1.2\hsize}R 
                                 c @{}}
\toprule
\multicolumn{2}{l}{\textbf{Browser:}    Chrome}         &                                 
        & \multicolumn{3}{c}{\textit{\textbf{All T2 tests are ran following T1-02}}}   \\
    \midrule
\thead[b]{Test\\ num.}  
    &   \thead[b]{Page}
        &   \thead[b]{Test\\ description}
            &   \thead[b]{Steps}
                &   \thead[b]{Expected\\ outcome}
                    &   \thead[b]{Pass?\\ (Y/N)}                \\
    \midrule
T2-01   &   Itinerary   &   Rename itinerary
                            &   Click edit icon, to the right of the itinerary name,
                                type 'mytinerary' and click the edit icon again
                                &   The name 'mytinerary' is now the displayed name for the itinerary
                                    &   Y                   \\
    \addlinespace
T2-02   &   Itinerary   & Rename itinerary
                            &   Click edit icon, to the right of the itinerary name,
                                type 'mytinerary' and press enter
                                &   The name 'mytinerary' is now the displayed name for the itinerary
                                    &   Y                   \\
    \addlinespace
T2-03   & Itinerary & Reset itinerary name
                        &   Repeat T2-02. Click the edit icon,
                            delete all text in the field and press enter
                            &   The original location 'London, United Kingdom'
                                is the displayed name for the itinerary
                                &   Y                       \\
    \addlinespace
T2-04   &   Itinerary   &   Reset itinerary
                            &   Click the 'Restart' button
                                &   Redirected to the landing page,
                                    there is an additional button with text
                                    "Revisit 'London, United Kingdom'"
                                    &   Y                   \\
    \addlinespace
T2-05   &   Itinerary   &   Reset and rejoin itinerary
                            &   Click the 'Restart' button,
                                then click the 'Revisit' button
                                &   Redirected to the landing page and
                                    then brought back to the itinerary page
                                    &   Y                   \\
    \addlinespace
T2-06   &   Itinerary   &   Access venue information
                            &   Click the name of the first itinerary item
                                &   Pop-up menu activates and displays information for the venue
                                    &   Y                   \\
    \addlinespace
T2-07   &   Itinerary   &   Close venue information
                            &   Repeat T2-06 and then click the 'x' icon
                                &   Pop-up menu closes and you are left on the itinerary page
                                    &   Y                   \\
    \addlinespace
T2-08   &   Itinerary   &   Close venue information
                            &   Repeat T2-06 and press the escape key
                                &   Pop-up menu closes and you are left on the itinerary page
                                    &   Y                   \\
    \addlinespace
T2-09   &   Itinerary   &   Next venue
                            &   Click the right arrow for an itinerary item
                                &   Venue name should change
                                    &   Y                   \\
    \addlinespace
T2-10   &   Itinerary   &   Previous venue
                            &   Repeat T2-09 and then click the left arrow of the same itinerary item                                & Venue name should be unchanged                                                                             & Y                             \\
    \bottomrule
\end{tabularx}
\end{table}
     \end{document}

附录: 如果表格长度超过一页,则可以使用包。它提供和环境tablex的组合:tabularxlongtable

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, ltablex, makecell, tabularx}
\renewcommand\theadfont{\bfseries\small}
\newcolumntype{R}{>{\RaggedRight}X}

  \begin{document}
{
    \small
    \setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{@{} ll >{\hsize=0.6\hsize}R 
                                    >{\hsize=1.2\hsize}R 
                                    >{\hsize=1.2\hsize}R 
                                 c @{}}
    \caption{My caption}
\label{my-label}    \\
\toprule
\multicolumn{2}{l}{\textbf{Browser:}    Chrome}         &                                 
        & \multicolumn{3}{c}{\textit{\textbf{All T2 tests are ran following T1-02}}}   \\
    \midrule
\thead[b]{Test\\ num.}  
    &   \thead[b]{Page}
        &   \thead[b]{Test\\ description}
            &   \thead[b]{Steps}
                &   \thead[b]{Expected\\ outcome}
                    &   \thead[b]{Pass?\\ (Y/N)}                \\
    \midrule
\endfirsthead
    \caption{My caption (cont.)}                                \\
    \toprule
\multicolumn{2}{l}{\textbf{Browser:}    Chrome}         &
        & \multicolumn{3}{c}{\textit{\textbf{All T2 tests are ran following T1-02}}}   \\
    \midrule
\thead[b]{Test\\ num.}
    &   \thead[b]{Page}
        &   \thead[b]{Test\\ description}
            &   \thead[b]{Steps}
                &   \thead[b]{Expected\\ outcome}
                    &   \thead[b]{Pass?\\ (Y/N)}                \\
    \midrule
\endhead
    \midrule[0.8pt]
\multicolumn{6}{r}{continue on the next page}\\
\endfoot
    \bottomrule
\endlastfoot
T2-01   &   Itinerary   &   Rename itinerary
                            &   Click edit icon, to the right of the itinerary name,
                                type 'mytinerary' and click the edit icon again
                                &   The name 'mytinerary' is now the displayed name for the itinerary
                                    &   Y                   \\
    \addlinespace
T2-02   &   Itinerary   & Rename itinerary
                            &   Click edit icon, to the right of the itinerary name,
                                type 'mytinerary' and press enter
                                &   The name 'mytinerary' is now the displayed name for the itinerary
                                    &   Y                   \\
    \addlinespace
T2-03   & Itinerary & Reset itinerary name
                        &   Repeat T2-02. Click the edit icon,
                            delete all text in the field and press enter
                            &   The original location 'London, United Kingdom'
                                is the displayed name for the itinerary
                                &   Y                       \\
    \addlinespace
T2-04   &   Itinerary   &   Reset itinerary
                            &   Click the 'Restart' button
                                &   Redirected to the landing page,
                                    there is an additional button with text
                                    "Revisit 'London, United Kingdom'"
                                    &   Y                   \\
    \addlinespace
T2-05   &   Itinerary   &   Reset and rejoin itinerary
                            &   Click the 'Restart' button,
                                then click the 'Revisit' button
                                &   Redirected to the landing page and
                                    then brought back to the itinerary page
                                    &   Y                   \\
    \addlinespace
T2-06   &   Itinerary   &   Access venue information
                            &   Click the name of the first itinerary item
                                &   Pop-up menu activates and displays information for the venue
                                    &   Y                   \\
    \addlinespace
T2-07   &   Itinerary   &   Close venue information
                            &   Repeat T2-06 and then click the 'x' icon
                                &   Pop-up menu closes and you are left on the itinerary page
                                    &   Y                   \\
    \addlinespace
T2-08   &   Itinerary   &   Close venue information
                            &   Repeat T2-06 and press the escape key
                                &   Pop-up menu closes and you are left on the itinerary page
                                    &   Y                   \\
    \addlinespace
T2-09   &   Itinerary   &   Next venue
                            &   Click the right arrow for an itinerary item
                                &   Venue name should change
                                    &   Y                   \\
    \addlinespace
T2-10   &   Itinerary   &   Previous venue
                            &   Repeat T2-09 and then click the left arrow of the same itinerary item 
                                & Venue name should be unchanged
                                    &   Y                   \\
    \addlinespace
T2-11  &    Itinerary   &   Open genre menu                 
                            &   Click the genre menu
                                &   Genre menu is displayed 
                                    &   Y                   \\
    \addlinespace
T2-12  &    Itinerary   &    Close genre menu                
                            &   Repeat T2-12 and click close button
                                &   Genre menu is not displayed
                                    &   Y                   \\
    \addlinespace
T2-13  &    Itinerary   &   Close genre menu                
                            &   Repeat T2-12 and click the genre menu 
                                &   Genre menu is not displayed
                                    &   Y                   \\
    \addlinespace
T2-14  &    Itinerary   &   Add genre venue options
                            &   Repeat T2-12 and click a glyph
                                &   Genre menu displayed, 
                                    clicked glyph has been highlighted and the venue has changed
                                    &   Y                   \\
    \addlinespace
T2-15  &    Itinerary   &   Pin item                        
                            &   Click the pin button for an itinerary item 
                                &   Pin button is filled                                    clicked glyph has been highlighted and the venue has changed
                                    &   Y                   \\
    \addlinespace                                
T2-16  &    Itinerary   &   Unpin Item 
                            &   Repeat T2-15 and then click the pin button again
                                &   Pin button is hollow
                                    &   Y                   \\
    \addlinespace
T2-17  &    Itinerary   &   Next venue for pinned item 
                            &   Repeat T2-15 and click an arrow button
                                &   No change in the itinerary item
                                    &   Y                   \\
    \addlinespace
T2-18  &    Itinerary   &   Open genre menu for pinned item 
                            &   Repeat T2-15 and click the genre menu
                                &   No change in the itinerary item
                                    &   Y                   \\
    \addlinespace
T2-19  &    Itinerary   &   Drag itinerary item             
                            &   Drag the first itinerary item over the last itinerary item
                                &   An orange bar should appear between the last two itinerary items
                                    &   Y                   \\
    \addlinespace
T2-20  &    Itinerary   &   Drag and drop itinerary item    
                            &   Drag the last itinerary item over the first itinerary item and drop it
                                &   The itinerary item that was dragged should now be at the top of the itinerary
                                    &   Y                   \\
    \addlinespace
T2-21  &    Itinerary   &   Expose travel elements          
                            &   Pin all 5 itinerary items
                                &   The travel elements should now be displayed 
                                    underneath all but the last itinerary item
                                    &   Y                   \\
\end{tabularx}
}
     \end{document}

在此处输入图片描述

相关内容