
在看到 Andrew Swann 對我之前問題的解決方案後:如何將該表格放入頁面中?我嘗試將其安裝到另一張桌子上:
\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish,mexico]{babel}
\usepackage[T1]{fontenc}
\usepackage{booktabs,longtable}
\usepackage{array}
\begin{document}
{\small\setlength\tabcolsep{5pt}
\begin{tabularx}{\linewidth}{ll*{2}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}}
\caption{Temario de actividades Secundaria} \\
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\addlinespace[2ex]
\endfirsthead
\multicolumn{4}{c}{\textsc{\tablename~\thetable}\enspace (continuación)}\\
\addlinespace[2ex]
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\endhead
\midrule
\multicolumn{4}{r}{Continúa}
\endfoot
\bottomrule
\endlastfoot
{\normalsize Día 1} & Bienvenida Encuadre Tema:Acuerdos de convivencia Ejercicios psicométricos & 1 & Pelota de esponja \emph{Brincón} Ejercicios psicométricos. Guía Eureka (Ver Anexo)\\
\addlinespace
{\normalsize Día 2} & Ejercicios psicométricos & 0 & Ejercicios psicométricos. Guía Eureka\\
\addlinespace
{\normalsize Día 3} & Ejercicios psicométricos & 0 & Ejercicios psicométricos\\
\addlinespace
{\normalsize Día 4} & Examen simulacro de ejercicios psicométricos en equipo & 0 & Ejercicios psicométricos. Guía verde actualizada 2000 (Ver Anexo).\\
\addlinespace
{\normalsize Día 5} & EXAMEN DE CONOCIMIENTOS GENERALES & & \\
\end{tabularx}
}
\end{document}
嗯,這就是我需要做的表,但我不知道如何做好。我的第一個問題是關於專欄聲明,從我之前的問題和我看到的其他解決方案中我對此進行了調整:
\begin{tabularx}{\linewidth}{ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}}
因為我需要 5 列,所以我知道該表有 3 個左對齊列,後來還有一個不合理的列 (RaggedRight) 和最後一個X專欄,我說得對嗎?但我不確定。程式碼ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
對我來說很難理解,有人可以解釋一下嗎?
更新
在評論和答案之後,我在表格中做了一些更正,我發現 aa 列沒有意義。但桌子的佈局很糟糕。我該如何修復它?如果我需要列表而不是段落,有沒有辦法列出或分隔單元格中的文字?
答案1
ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
是
ll
兩列單行左對齊條目,然後
*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
三份>{\RaggedRight\arraybackslash\hspace{0pt}}X
其中每一個基本上都是一X
列,p{...}
用來自動計算寬度。
中的標記>{...}
應用於每個單元格的開頭。在這種情況下,即
\RaggedRight\arraybackslash\hspace{0pt}
\RaggedRight
\raggedright
是from包的改進版本ragged2e
。
\arraybackslash
在tabularx
其中定義的重新定義\\
為結束表格行(這是其在表格中的正常定義,但是\ragedright
等\RaggedRight
在本地重新定義它以形成不規則的文本行結束,這在這裡是不需要的。
用 開始一個段落\hspace{0pt}
是一個老技巧,在第一個單字之前放置一個空格,這允許 TeX 用連字符連接段落中的第一個單字。 (TeX 的連字符演算法不會考慮第一個單詞,這可能確實是一個錯誤,但 TeX 已凍結並且不會改變該行為。
答案2
大衛·卡萊爾已經回答了你的第一個問題。所以我會盡力幫助您解決其他問題。您的 MWE 有一些錯誤,例如\caption
after \begin{tabularx} ...
,但它沒有\end{document}
。最值得注意的是,對我來說,不清楚您是否喜歡longtabe
在浮動環境中擁有(分佈在更多頁面上)或只是簡單的表格。我假設最後一種情況就是這種情況,並按照以下方式重新製作您的 MWE:
\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
%\usepackage[spanish,mexico]{babel} i haven't it ..
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{booktabs,tabularx}
\usepackage[labelsep=colon,
labelfont={bf},
justification=raggedright,
singlelinecheck=false]{caption}% added for caption custumization
%% just for shoving test result, erase this two line in final text
\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\begin{table}
\setlength\tabcolsep{3pt}
\small
\caption{Temario de actividades Secundaria}
\begin{tabularx}{\linewidth}{
c% first column, I change "l" to "c" (matter of taste)
>{\setlength\hsize{1.2\hsize}}L% I make it wider
c% third column, I change it from X to c; Is it really necessary since it is empty?,
% does it should has equal width as second and last column?
>{\setlength\hsize{.6\hsize}}C% I make it narrower
>{\setlength\hsize{1.2\hsize}}L% I make it wider
}
\toprule
Horario % I remove \textsc, for better looking of table
& Ejercicio
& Objetivo
& Grado de riesgo
& Material \\
\midrule
Día 1
& Bienvenida Encuadre Tema: Acuerdos de convivencia Ejercicios psicométricos
& & 1
& Pelota de esponja \emph{Brincón} Ejercicios psicométricos.
Guía Eureka (Ver Anexo) \\
\addlinespace
Día 2
& Ejercicios psicométricos
& & 0
& Ejercicios psicométricos. Guía Eureka \\
\addlinespace
Día 3
& Ejercicios psicométricos
& & 0
& Ejercicios psicométricos \\
\addlinespace
Día 4
& Examen simulacro de ejercicios psicométricos en equipo
& & 0
& Ejercicios psicométricos.
Guía verde actualizada 2000 (Ver Anexo). \\
\addlinespace
Día 5
& Examen de conocimientos generales, gute
& & & \textbullet\ emulation of itemize
environment (to show
possible solutions) \newline
\textbullet\ second item \newline \textbullet\ third item \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
在程式碼中,我添加了一些註釋,試圖澄清我在做什麼以及旁邊提到的我不清楚的內容。正如你所看到的,該表被放入表環境中,我還建議在文件序言中定義新的列類型。
編輯: Iraultza Bellaustegigoitia,當您開始設計表格時——這是使用 LaTeX 時最具挑戰性的任務之一——您需要做出一些決定:
- 表格是否適合一頁,或太大,在更多頁面上會損壞
- 表格是否可以浮動在文字中
- 桌子應該有規定的寬度
考慮到上述問題的答案,您選擇表格環境,例如tabularx
一頁上的表格,longtable
以獲得更大的結果。如果您不熟悉所選的軟體包,請閱讀(至少簡要地)軟體包隨附的文件。
在設計表格時考慮一些簡單的規則:
- 較新的混合了不同套件的特定功能(例如,使用
longtable
中的頁首/頁尾定義tabularx
)。array
和package是例外booktabs
,它們旨在支援其他表格包。 - 在表格中使用不同的字體大小是個壞主意
我重新設計了我的 MWE,添加了簡單模擬表格單元格中列表的示例(對於要求更高的佈局,我建議使用一些列表包作為enumitem
),並添加由它生成的表格的新圖片。我希望它與您想要實現的目標接近,並且我的添加會對您有所幫助。
答案3
好吧,在這張桌子上掙扎了一整天之後,感謝大衛·卡萊爾和 Zarco 技巧的善意回應和解釋,我得到了我想要的桌子。
我所做的如下:
\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish,mexico]{babel}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{array,caption}
\captionsetup{labelfont=sc,textfont=it}
\usepackage{tikz}
\usepackage{ltablex}
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{longtable}
\newcolumntype{C}{>{\centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
\begin{document}
{\small\setlength\tabcolsep{5pt}
\begin{tabularx}{\linewidth}{cLCL} % {lc*{2}L}
\caption{Temario de actividades Secundaria} \\
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\addlinespace[2ex]
\endfirsthead
\multicolumn{4}{c}{\textsc{\tablename~\thetable}\enspace (continuación)}\\
\addlinespace[2ex]
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\endhead
\midrule
\multicolumn{4}{r}{Continúa}
\endfoot
\bottomrule
\endlastfoot
{\normalsize Día 1} & Bienvenida\par Encuadre\par Tema:\par Acuerdos de convivencia\par Ejercicios psicométricos & 1 & Pelota de esponja\par \emph{Brincón}\par Ejercicios psicométricos\par Guía Eureka (Ver Anexo)\\
\addlinespace
{\normalsize Día 2} & Ejercicios psicométricos & 0 & Ejercicios psicométricos. Guía Eureka\\
\addlinespace
{\normalsize Día 3} & Ejercicios psicométricos & 0 & Ejercicios psicométricos\\
\addlinespace
{\normalsize Día 4} & Examen simulacro de ejercicios psicométricos en equipo & 0 & Ejercicios psicométricos. Guía verde actualizada 2000 (Ver Anexo).\\
\addlinespace
{\normalsize Día 5} & \multicolumn{3}{c}{EXAMEN DE CONOCIMIENTOS GENERALES} \\
\addlinespace
{\normalsize Día 6} & Autoconcepto \par Autoestima \par Elaboración de mi propio regalo & 2 & Papel bond\par Plumones\par Pegamento\par Tijeras\par Crayolas \\
\end{tabularx}
}
\end{document}
我的另一個問題是如何在此表的儲存格中登記文字。我不認為使用類似itemize
或enumerate
嵌套在其中的環境是一個好主意,也就是說,我認為它不能正確編譯。很多時候,使用分隔文字很容易\\
,但正如表格中區分行的方式一樣,這兩種方法似乎都不起作用。最後嘗試了一下,\par
確實有效,但不知道還有沒有更好的方法。