如何在换行环境中将标题与表格左侧对齐

如何在换行环境中将标题与表格左侧对齐

我正在尝试寻找以下问题的解决方案:

我在包装环境 (wraptable) 中有一个表格。我需要表格标题与表格左对齐。另外,我不希望标题超出表格本身的长度。现在结果如下所示:

在此处输入图片描述

我在在线论坛上找到了一个使用 floatrow 包的解决方案。然而,这并不奏效,结果如下:

在此处输入图片描述

我究竟做错了什么?

我的 MWE(很抱歉。我知道这并不是真正的“最小”。但我不确定哪些包可以删除以使 MWE 继续工作。)

\documentclass[12pt, titlepage, a4paper, oneside, headsepline]{scrreprt} % headsepline 



\usepackage{scrhack} % verbessert einige Fremdpakete und das Zusammenspiel von einigen Paketen mit KOMA-Script
\usepackage{graphicx} % Graphiken einfügen
\usepackage{wrapfig} % Text fließt um Figure
\usepackage{caption} % Überschriften formatieren
\usepackage{booktabs} % Tabelle
\usepackage[section]{placeins} %Floatbarriere

\usepackage{multirow} %für Tabellen
\usepackage{makecell} %fette hline
\usepackage[singlelinecheck=false]{caption} %Tabellencaption linksbündig
% \usepackage{floatrow} % Tabellencaption in wrapped umgebung

\usepackage{threeparttable} %Tabellenüberschrift linksbündig an Tabelle

\usepackage{caption} % doopelte hline
\usepackage{booktabs}
\newcommand\doubleRule{\toprule\toprule}
\newcommand\doublerule{\toprule\specialrule{\heavyrulewidth}{\doublerulesep}{0.95em}}
\usepackage{tabularx}

\usepackage{enumitem}
\newlist{mytabitem}{itemize}{1}
\setlist[mytabitem]{nosep,leftmargin=*,before=\vspace{-0.5\baselineskip},after=\vspace{-1\baselineskip}, label=\textbullet}
\newcommand{\tabitem}[1]{\begin{mytabitem}\item #1\end{mytabitem}}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\usepackage{makecell}


\usepackage[left=3cm,right=2cm,top=1cm,bottom=1cm]{geometry} 

\usepackage[onehalfspacing]{setspace}

我的桌子:

\begin{wraptable}{r}{0.7\textwidth}
\renewcommand{\arraystretch}{0.7} % this reduces the vertical spacing between rows
\linespread{0.95} \selectfont \centering
% \ttabbox
\caption{Perceived family influence on organizational identity}
\label{table:Perceived family influence on organizational identity}


\begin{tabular}{p{4cm} p{2.5cm}}
\toprule
\multicolumn{1}{l}{~} & \multicolumn{1}{l}{Interviewees}\\
\midrule
\vtop{\hbox{\strut Family influence as most important}\hbox{\strut factor influencing OI}} & [14], [15] \\
\vtop{\hbox{\strut Family influence has great impact}\hbox{\strut on OI}} & [] \\
\vtop{\hbox{\strut Family influence can have impact}\hbox{\strut on OI}} & [] \\
\bottomrule
\end{tabular}
\end{wraptable}

感谢您的帮助!

莉亚

答案1

既然您似乎已经了解该threeparttable软件包以及它的一个功能(\usepackage{threeparttable} %Tabellenüberschrift linksbündig an Tabelle),为什么不使用它呢?

在此处输入图片描述

\documentclass[12pt, titlepage, a4paper, oneside, headsepline]{scrreprt} % headsepline 

\usepackage{wrapfig} % Text fließt um Figure

\usepackage[singlelinecheck=false]{caption} %Tabellencaption linksbündig
\usepackage{threeparttable} %Tabellenüberschrift linksbündig an Tabelle
\usepackage{booktabs}

\usepackage[left=3cm,right=2cm,top=1cm,bottom=1cm]{geometry} 
\usepackage[onehalfspacing]{setspace}

\usepackage{lipsum} % For filler text. Don't use in actual document.


\begin{document}
\lipsum[1]
\lipsum[2]

\begin{wraptable}{r}{0.7\textwidth}
\renewcommand{\arraystretch}{0.7} % this reduces the vertical spacing between rows
\linespread{0.95} \selectfont \centering
\begin{threeparttable}
\caption{Perceived family influence on organizational identity}
\label{table:Perceived family influence on organizational identity}
\begin{tabular}{p{4cm} p{2.5cm}}
\toprule
\multicolumn{1}{l}{~} & \multicolumn{1}{l}{Interviewees}\\
\midrule
\vtop{\hbox{\strut Family influence as most important}\hbox{\strut factor influencing OI}} & [14], [15] \\
\vtop{\hbox{\strut Family influence has great impact}\hbox{\strut on OI}} & [] \\
\vtop{\hbox{\strut Family influence can have impact}\hbox{\strut on OI}} & [] \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{wraptable}

\lipsum[3]

\end{document}

由于表格的代码非常混乱,包含基本上多余的\hbox命令,因此我建议采用以下方法之一:

在此处输入图片描述

\documentclass[12pt, titlepage, a4paper, oneside, headsepline]{scrreprt} % headsepline 

\usepackage{wrapfig} % Text fließt um Figure

\usepackage[singlelinecheck=false]{caption} %Tabellencaption linksbündig
\usepackage{threeparttable} %Tabellenüberschrift linksbündig an Tabelle
\usepackage{booktabs}

\usepackage[left=3cm,right=2cm,top=1cm,bottom=1cm]{geometry} 
\usepackage[onehalfspacing]{setspace}

\usepackage{lipsum} % For filler text. Don't use in actual document.
\usepackage{tabularx}

\begin{document}
\lipsum[1]

\begin{wraptable}{r}{0.7\textwidth}
  \begin{threeparttable}
    \caption{Perceived family influence on organizational identity}
    \label{table:Perceived family influence on organizational identity}
    \begin{tabular}{>{\raggedright\arraybackslash}p{6.5cm} p{2.5cm}}
      \toprule 
        & Interviewees \\
      \midrule
      Family influence as most important factor influencing OI & [14], [15] \\
      Family influence has great impact \newline on OI & [] \\
      Family influence can have impact \newline on OI & [] \\
      \bottomrule
    \end{tabular}
  \end{threeparttable}
\end{wraptable}

\lipsum[2]

\begin{wraptable}{r}{0.7\textwidth}
  \begin{threeparttable}
    \caption{Perceived family influence on organizational identity}
    \label{table:Perceived family influence on organizational identity}
    \begin{tabularx}{\linewidth}{>{\raggedright\arraybackslash}Xl}
      \toprule 
        & Interviewees \\
      \midrule
      Family influence as most important factor influencing OI & [14], [15] \\
      Family influence has great impact \newline on OI & [] \\
      Family influence can have impact \newline on OI & [] \\
      \bottomrule
    \end{tabularx}
  \end{threeparttable}
\end{wraptable}

\lipsum[3]

\end{document} 

编辑评论中关于请求的内容:

我建议不要手动摆弄行距,而是执行以下操作:

\usepackage{etoolbox}\AtBeginEnvironment{wraptable}{\singlespacing}wraptable自动将文档中每个环境中的行距​​重置为单倍行距。可以\addlinespacebooktabs包中根据需要在制表中添加一些垂直 khite 空间:

在此处输入图片描述

\documentclass[12pt, titlepage, a4paper, oneside, headsepline]{scrreprt} % headsepline 

\usepackage{wrapfig} % Text fließt um Figure

\usepackage[singlelinecheck=false]{caption} %Tabellencaption linksbündig
\usepackage{threeparttable} %Tabellenüberschrift linksbündig an Tabelle
\usepackage{booktabs}

\usepackage[left=3cm,right=2cm,top=1cm,bottom=1cm]{geometry} 
\usepackage[onehalfspacing]{setspace}

\usepackage{array}
\usepackage{etoolbox}
\AtBeginEnvironment{wraptable}{\singlespacing}

\begin{document}

\begin{wraptable}{r}{0.7\textwidth}

  \begin{threeparttable}
    \caption{Perceived family influence on organizational identity}
    \label{table:Perceived family influence on organizational identity}
    \begin{tabular}{>{\raggedright\arraybackslash}p{6.5cm} p{2.5cm}}
      \toprule 
        & Interviewees \\
      \midrule
      Family influence as most important factor influencing OI & [14], [15] \\ \addlinespace
      Family influence has great impact \newline on OI & [] \\ \addlinespace
      Family influence can have impact \newline on OI & [] \\
      \bottomrule
    \end{tabular}
  \end{threeparttable}
\end{wraptable}

\end{document} 

答案2

对于非常窄的列,\sloppy这是 SOP。您可以在段落之间使用 关闭它\fussy

大多数这些包与本示例无关,应该被删除以创建最小示例。

\documentclass[12pt, titlepage, a4paper, oneside, headsepline]{scrreprt} % headsepline 

\usepackage{scrhack} % verbessert einige Fremdpakete und das Zusammenspiel von einigen Paketen mit KOMA-Script
\usepackage{graphicx} % Graphiken einfügen
\usepackage{wrapfig} % Text fließt um Figure
\usepackage{caption} % Überschriften formatieren
\usepackage{booktabs} % Tabelle
\usepackage[section]{placeins} %Floatbarriere

\usepackage{multirow} %für Tabellen
\usepackage{makecell} %fette hline
\usepackage[singlelinecheck=false]{caption} %Tabellencaption linksbündig
% \usepackage{floatrow} % Tabellencaption in wrapped umgebung

\usepackage{threeparttable} %Tabellenüberschrift linksbündig an Tabelle

\usepackage{caption} % doopelte hline
\usepackage{booktabs}
\newcommand\doubleRule{\toprule\toprule}
\newcommand\doublerule{\toprule\specialrule{\heavyrulewidth}{\doublerulesep}{0.95em}}
\usepackage{tabularx}

\usepackage{enumitem}
\newlist{mytabitem}{itemize}{1}
\setlist[mytabitem]{nosep,leftmargin=*,before=\vspace{-0.5\baselineskip},after=\vspace{-1\baselineskip}, label=\textbullet}
\newcommand{\tabitem}[1]{\begin{mytabitem}\item #1\end{mytabitem}}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\usepackage{makecell}

\usepackage[left=3cm,right=2cm,top=1cm,bottom=1cm]{geometry} 

\usepackage[onehalfspacing]{setspace}% really?

\usepackage{blindtext}% MWE only
\newsavebox{\tempbox}

\begin{document}

\savebox{\tempbox}{% measure width
\begin{tabular}{p{4cm} p{2.5cm}}
\toprule
\multicolumn{1}{l}{~} & \multicolumn{1}{l}{Interviewees}\\
\midrule
\vtop{\hbox{\strut Family influence as most important}\hbox{\strut factor influencing OI}} & [14], [15] \\
\vtop{\hbox{\strut Family influence has great impact}\hbox{\strut on OI}} & [] \\
\vtop{\hbox{\strut Family influence can have impact}\hbox{\strut on OI}} & [] \\
\bottomrule
\end{tabular}}%
\begin{wraptable}{r}{\wd\tempbox}% use width of tabular
\renewcommand{\arraystretch}{0.7} % this reduces the vertical spacing between rows
\linespread{0.95} \selectfont \centering
% \ttabbox
\caption{Perceived family influence on organizational identity}
\label{table:Perceived family influence on organizational identity}
\usebox\tempbox
\end{wraptable}

\sloppy\blindtext
\end{document}

相关内容