我想制作一个命令,使表格具有固定宽度,文本在左侧垂直排列,顶部水平排列。
我希望表格看起来像这样
但它看起来像这样
代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[danish]{babel}
\usepackage{lscape}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{float}
\usepackage[top=2.81cm, bottom=2.75cm,right=2cm, left=2cm]{geometry}
\usepackage{url}
\usepackage[hidelinks]{hyperref}
\hypersetup{breaklinks=true}
\usepackage{setspace}
\onehalfspacing
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{setspace}
\onehalfspacing
\usepackage{url}
\usepackage[hidelinks]{hyperref}
\hypersetup{breaklinks=true}
\newcounter{rowcntr}[table]
\makeatletter
\usepackage{longtable}
\newcolumntype{L}[2]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[2]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\renewcommand{\therowcntr}{\@arabic{\numexpr\c@table+1}.\arabic{rowcntr}}
\makeatother
\newcolumntype{N}{>{\refstepcounter{rowcntr}\therowcntr}c}
\AtBeginEnvironment{tabular}{\setcounter{rowcntr}{0}}
\begin{document}
\begin{center}
\begin{longtable}{|N| l | L{7.6cm} | L{7.6cm} |}
\hline
\multicolumn{2}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Why}} \\ \hline
\multicolumn{4}{|c|}{Interview fase 1 - Indledende}\\ \hline
\multicolumn{4}{|C{17.5cm}|}{\textit{Text TextTextTextTextText TextTextTextTextTextTextTextTextTextTextText TextText TextTextText TextTextTextTextTextTextTextTextTextText Text Text Text Text Text Text Text Text }}\\ \hline
\label{que:1} & A & Why is it you think ...? & This is a good question.\\
\label{que:2} & C & Why is it you think Text text Text textText textText text & This is a good question.\\
\label{que:3} & E & Text text Text text Text text & Text text Text textText text Text textText text Text text Text text Text textText text Text text Text text.\\ \hline
\caption {Questions} \label{tab:interviewspg}
\end{longtable}
\end{center}
\end{document}
答案1
删除所有重复的包和所有与您的表无关的包,并从表中删除所有多余的代码后...并考虑到我和 Mico 上面的评论,我得到了下表。这是您要找的吗?
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[showframe,% for this example only: show page layout
top=2.81cm, bottom=2.75cm,
right=2cm, left=2cm]{geometry}
\usepackage{setspace}
\onehalfspacing
\usepackage{etoolbox}
\usepackage{array,longtable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{\dimexpr#1-2\tabcolsep-\arrayrulewidth}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{\dimexpr#1-2\tabcolsep-\arrayrulewidth}}
\newcounter{rowcntr}[table]
\renewcommand{\therowcntr}{\arabic{table}.\arabic{rowcntr}}
\newcolumntype{N}[1]{>{\refstepcounter{rowcntr}\therowcntr\centering}p{\dimexpr#1-2\tabcolsep-\arrayrulewidth}}
\AtBeginEnvironment{tabular}{\setcounter{rowcntr}{0}}
\begin{document}
some text
{ \sffamily
\begin{longtable}{| N{0.05\linewidth}
| C{0.05\linewidth}
| L{0.45\linewidth}
| L{0.45\linewidth} |}
\hline
& & \hfil\textbf{Question} & \hfil\textbf{Why} \\ \hline
\multicolumn{4}{|c|}{Interview phase 1 - Indledende} \\ \hline
\multicolumn{4}{|C{\linewidth}|}{Text TextTextTextTextText
TextTextTextTextTextTextTextTextTextTextText
TextText TextTextText TextTextTextTextTextTextTextTextTextText
Text Text Text Text Text
Text Text Text} \\ \hline
\label{que:1} & A & Why is it you think ...\dots? & This is a good question. \\
\label{que:2} & C & Why is it you think Text text
Text textText textText text & This is a good question. \\
\label{que:3} & E & Text textText text Text text & Text text Text textText
text Text textText text Text text Text text Text textText text Text text Text text. \\ \hline
\caption{Questions}
\label{tab:interviewspg}
\end{longtable}
}
\end{document}