我在 LibreOffice calc 中有一個簡單的表格,我嘗試使用 Calc2Latex 巨集將其轉換為乳膠。
然後我嘗試使用 Latex 來改進它。但是我無法正確獲取文字!
這就是我希望表中的文字:
例如,在第一列中,劃分了「每個來源每分鐘的訊息」。
然而,在我的乳膠生成的表中,這種情況不會發生!這一切都是一團糟:
我嘗試使用修復問題tabularx
,並且在某個地方讀到了我不應該使用的內容multicolumn
,但我仍然是新手,我不知道如何解決這個問題!
這是我的 MWE:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\usepackage[margin=2.54cm]{geometry}
\usepackage{graphicx,booktabs,tabularx}
\usepackage[table]{xcolor}
\usepackage{array}
%define some nice colors
\definecolor{middleware_green}{RGB}{82, 119, 17}
\definecolor{middleware_white}{RGB}{255, 255, 255}
\definecolor{middleware_light_gray}{RGB}{239, 239, 239}
\definecolor{middleware_dark_gray}{RGB}{153, 153, 153}
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\newcolumntype{F}{|>{\leavevmode\ignorespaces\raggedright\sffamily\bfseries}p{2.5cm}}%
\newcolumntype{R}{|>{\leavevmode\ignorespaces\raggedright\arraybackslash\sffamily}X}%
\newcolumntype{L}{|>{\leavevmode\ignorespaces\raggedleft\arraybackslash\sffamily}X}%
\newcolumntype{C}{|>{\leavevmode\ignorespaces\centering\arraybackslash\sffamily}X|}%
\rowcolors{2}{middleware_white}{middleware_light_gray}
\begin{document}
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{|R|L|L|L|}
\hline\rowcolor{middleware_green}
\multicolumn{ 4}{|c|}{\textcolor{white}{\textbf{1 Source, 1 Session, 1 Client, Exp0}}} \\ \hline
\multicolumn{1}{|c|}{\textbf{Messages per minute per source}} & \multicolumn{1}{c|}{\textbf{Middleware Exec Time (s)}} & \multicolumn{1}{c|}{\textbf{Delay (s)}} & \multicolumn{1}{c|}{\textbf{Average Delay (s)}} \\ \hline
\multicolumn{ 1}{|r|}{60} & 60 & 0 & \multicolumn{ 1}{r|}{0.00} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 60 & 0 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 60 & 0 & \multicolumn{ 1}{l|}{} \\ \hline
\multicolumn{ 1}{|r|}{120} & 60 & 0 & \multicolumn{ 1}{r|}{0.00} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 60 & 0 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 60 & 0 & \multicolumn{ 1}{l|}{} \\ \hline
\multicolumn{ 1}{|r|}{240} & 60 & 0 & \multicolumn{ 1}{r|}{0.00} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 60 & 0 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 60 & 0 & \multicolumn{ 1}{l|}{} \\ \hline
\multicolumn{ 1}{|r|}{480} & 69 & 9 & \multicolumn{ 1}{r|}{16.67} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 69 & 9 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 92 & 32 & \multicolumn{ 1}{l|}{} \\ \hline
\multicolumn{ 1}{|r|}{1000} & 159 & 99 & \multicolumn{ 1}{r|}{109.67} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 173 & 113 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 177 & 117 & \multicolumn{ 1}{l|}{} \\ \hline
\multicolumn{ 1}{|r|}{2000} & 391 & 331 & \multicolumn{ 1}{r|}{311.00} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 383 & 323 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 339 & 279 & \multicolumn{ 1}{l|}{} \\ \hline
\multicolumn{ 1}{|r|}{4000} & 561 & 501 & \multicolumn{ 1}{r|}{512.33} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 631 & 501 & \multicolumn{ 1}{l|}{} \\ \cline{ 2- 3}
\multicolumn{ 1}{|l|}{} & 595 & 535 & \multicolumn{ 1}{l|}{} \\ \hline
\end{tabularx}
\label{}
\caption{}
\end{table}
\end{document}
我想讓列變小的主要原因是這樣它們可以佔用更少的空間,所以希望我可以在它們旁邊放置一些文字或將 2 個表格一個挨一個地放置!
答案1
列X
允許其內容被破壞,但是當您這樣做時,\multicolumn{1}{c}{Lots of text}
您會覆寫該列說明符。該單元格將表現為一c
列,不允許換行。
若要將列標題居中,同時仍允許換行,並使列的其餘部分右對齊,請\multicolumn
在C
列中使用 a ,例如\multicolumn{1}{C}{\textbf{Messages per minute per source}}
。
其餘的\multicolumn{1}{..
東西我認為你可以刪除。在下面的完整程式碼中,一張表格帶有垂直線,一張沒有垂直線。我認為你可以使用沒有的那個,但我會讓你決定。
這些桌子的位置是0.45\textwidth
,因此它們可以更寬一些,並且仍然可以容納兩個人並排。如果您不需要,它們當然可以更寬。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\usepackage[margin=2.54cm]{geometry}
\usepackage{graphicx,booktabs,tabularx}
\usepackage[table]{xcolor}
\usepackage{array}
%define some nice colors
\definecolor{middleware_green}{RGB}{82, 119, 17}
\definecolor{middleware_white}{RGB}{255, 255, 255}
\definecolor{middleware_light_gray}{RGB}{239, 239, 239}
\definecolor{middleware_dark_gray}{RGB}{153, 153, 153}
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\newcolumntype{F}{>{\leavevmode\ignorespaces\raggedright\sffamily\bfseries}p{2.5cm}}%
\newcolumntype{R}{>{\leavevmode\ignorespaces\raggedright\arraybackslash\sffamily}X}%
\newcolumntype{L}{>{\leavevmode\ignorespaces\raggedleft\arraybackslash\sffamily}X}%
\newcolumntype{C}{>{\leavevmode\ignorespaces\centering\arraybackslash\sffamily}X}%
\rowcolors{2}{middleware_white}{middleware_light_gray}
\begin{document}
\begin{table}
\centering
\begin{tabularx}{.45\textwidth}{LLLL}
\hline\rowcolor{middleware_green}
\multicolumn{4}{|c|}{\textcolor{white}{\textbf{1 Source, 1 Session, 1 Client, Exp0}}} \\ \hline
\multicolumn{1}{C}{\textbf{Messages per minute per source}} &
\multicolumn{1}{C}{\textbf{Middle\-ware Exec Time (s)}} &
\multicolumn{1}{C}{\textbf{Delay (s)}} &
\multicolumn{1}{C}{\textbf{Average Delay (s)}} \\ \hline
60 & 60 & 0 & 0.00 \\ \cline{ 2- 3}
& 60 & 0 & \\ \cline{ 2- 3}
& 60 & 0 & \\ \hline
120 & 60 & 0 & 0.00 \\ \cline{ 2- 3}
& 60 & 0 & \\ \cline{ 2- 3}
& 60 & 0 & \\ \hline
240 & 60 & 0 & 0.00 \\ \cline{ 2- 3}
& 60 & 0 & \\ \cline{ 2- 3}
& 60 & 0 & \\ \hline
480 & 69 & 9 & 16.67 \\ \cline{ 2- 3}
& 69 & 9 & \\ \cline{ 2- 3}
& 92 & 32 & \\ \hline
1000 & 159 & 99 & 109.67 \\ \cline{ 2- 3}
& 173 & 113 & \\ \cline{ 2- 3}
& 177 & 117 & \\ \hline
2000 & 391 & 331 & 311.00 \\ \cline{ 2- 3}
& 383 & 323 & \\ \cline{ 2- 3}
& 339 & 279 & \\ \hline
4000 & 561 & 501 & 512.33 \\ \cline{ 2- 3}
& 631 & 501 & \\ \cline{ 2- 3}
& 595 & 535 & \\ \hline
\end{tabularx}
\begin{tabularx}{.45\textwidth}{|L|L|L|L|}
\hline\rowcolor{middleware_green}
\multicolumn{4}{|c|}{\textcolor{white}{\textbf{1 Source, 1 Session, 1 Client, Exp0}}} \\ \hline
\multicolumn{1}{|C|}{\textbf{Messages per minute per source}} &
\multicolumn{1}{C|}{\textbf{Middle\-ware Exec Time (s)}} &
\multicolumn{1}{C|}{\textbf{Delay (s)}} &
\multicolumn{1}{C|}{\textbf{Average Delay (s)}} \\ \hline
60 & 60 & 0 & 0.00 \\ \cline{ 2- 3}
& 60 & 0 & \\ \cline{ 2- 3}
& 60 & 0 & \\ \hline
120 & 60 & 0 & 0.00 \\ \cline{ 2- 3}
& 60 & 0 & \\ \cline{ 2- 3}
& 60 & 0 & \\ \hline
240 & 60 & 0 & 0.00 \\ \cline{ 2- 3}
& 60 & 0 & \\ \cline{ 2- 3}
& 60 & 0 & \\ \hline
480 & 69 & 9 & 16.67 \\ \cline{ 2- 3}
& 69 & 9 & \\ \cline{ 2- 3}
& 92 & 32 & \\ \hline
1000 & 159 & 99 & 109.67 \\ \cline{ 2- 3}
& 173 & 113 & \\ \cline{ 2- 3}
& 177 & 117 & \\ \hline
2000 & 391 & 331 & 311.00 \\ \cline{ 2- 3}
& 383 & 323 & \\ \cline{ 2- 3}
& 339 & 279 & \\ \hline
4000 & 561 & 501 & 512.33 \\ \cline{ 2- 3}
& 631 & 501 & \\ \cline{ 2- 3}
& 595 & 535 & \\ \hline
\end{tabularx}
\caption{Look, two tables!}
\end{table}
\end{document}
答案2
我提出這個解決方案,雖然makecell
它遠非完美。不過,我認為這很有趣,因為程式碼更加緊湊。
它有顏色問題:前兩行很好,但後面的行並不完全著色,原因我不明白,因為程式碼與第二行的程式碼沒有根本不同(我測試了替換\multirow
命令在第 4 行中\makecell
,結果表中沒有任何更改)。
所以如果有人能解釋一下問題是什麼...
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{microtype}
\usepackage[margin=2.54cm]{geometry}
\usepackage{graphicx,tabularx}%booktabs,
\usepackage{array}
%define some nice colors
\usepackage[font = sf]{caption}
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\renewcommand{\cellalign}{rc}
\usepackage[table, svgnames]{xcolor}
\definecolor{middleware_green}{RGB}{82, 119, 17}
\definecolor{middleware_white}{RGB}{255, 255, 255}
\definecolor{middleware_light_gray}{RGB}{239, 239, 239}
\definecolor{middleware_dark_gray}{RGB}{153, 153, 153}
\usepackage{colortbl}
\rowcolors{2}{White}{Olive!15!}
\begin{document}
\begin{table}[htbp]
\sffamily\centering
\label{}
\caption{}
\begin{tabular}{|r|r|r|r|}%
\hline\rowcolor{middleware_green}
\multicolumn{ 4}{|c|}{\Gape[8pt]{\textcolor{white}{\textbf{1 Source, 1 Session, 1 Client, Exp0}}}} \\ %
\hline%
\makecell*{Messages\\ per minute\\ per source} & \makecell{Middleware Exec\\ Time (s)} & \makecell{Delay (s)}& \makecell{Average\\ Delay (s)} \\
\hline
\multirowcell{3}{360} & \makecell{60\\ 60\\60} & \makecell{0\\0\\0} & \multirowcell{3}{0.00} \\
\hline\rowcolor{Olive!20!}%%
\multirowcell{3}{120} & \makecell*{60\\60\\60} & \makecell{0\\0\\0} & \multirowcell{3}{0.00} \\%
\hline
\multirowcell{3}{240} & \makecell*{60\\60\\60} & \makecell{0\\0\\0} & \multirowcell{3}{0.00} \\
\hline
\multirowcell{3}{480} & \makecell*{69\\69\\92} & \makecell{9\\9\\32}& \multirowcell{3}{16.67} \\
\hline
\multirowcell{3}{1000} & \makecell*{159\\173\\177} & \makecell{99\\113\\117} & \multirowcell{3}{109.67} \\
\hline
\multirowcell{3}{2000} & \makecell*{391\\383\\339} & \makecell{331\\323\\279} & \multirowcell{3}{311.00} \\
\hline
\multirowcell{3}{4000} & \makecell*{561\\631\\595} & \makecell{501\\501\\535} & \multirowcell{3}{512.33} \\
\hline
\end{tabular}
\end{table}
\end{document}