[英]Vertical lines and width table latex
我復制的文章的表,我需要的表是紙張的文本的寬度並添加文字下方的垂直線 ,我附上我的代碼。
% Please add the following required packages to your document preamble:
% \usepackage{booktabs}
\begin{table}[h]
\centering
\label{my-label}
\begin{tabular}{@{}l@{}}
\toprule
\textbf{Algorithm 2:} The Forward algorithm \\ \midrule
\textbf{Initialization:} \\
\ $\alpha_1(i) = \pi_i bi(O_1), \ 1 \leq i \leq K$ \\
\\
\textbf{Recursion:} \\
\textbf{for} t = 1,..., T-1 \textbf{do} \\
\ \ \ \textbf{for} j = 1,..., K do \\
\ \ \ \ \ \ \ $\alpha_{t+1}(j) = \left [\sum_{i=1}^{k} \alpha_t (i) \alpha_{ij},\right ] b_j(O_{t+1})$ \\
\ \ \ \textbf{end} \\
\textbf{end} \\
\\
\textbf{Result:} $P(O_{1:T}) = \sum_{i=1}^N \alpha_T (i)$ \\ \bottomrule
\end{tabular}
\end{table}
我期望的結果是上乘圖像中的結果。 任何想法。
添加\\vline
並使用\\vline
usepackage{tabularx}
寬度文本。
\begin{table}[h]
\centering
\label{my-label}
\begin{tabularx}{\textwidth}{X}
\toprule
\textbf{Algorithm 2:} The Forward algorithm \\ \midrule
\textbf{Initialization:} \\
\ $\alpha_1(i) = \pi_i bi(O_1), \ 1 \leq i \leq K$ \\
\\
\textbf{Recursion:} \\
\textbf{for} $t = 1,..., T-1$ \textbf{do} \\
\ \ \vline \ \ \textbf{for} $j = 1,..., K$ \textbf{do} \\
\ \ \vline \ \ \ \ \vline \ \ $\alpha_{t+1}(j) = \left [\sum_{i=1}^{k} \alpha_t (i) \alpha_{ij},\right ] b_j(O_{t+1})$ \\
\ \ \vline \ \ \textbf{end} \\
\textbf{end} \\
\\
\textbf{Result:} $P(O_{1:T}) = \sum_{i=1}^N \alpha_T (i)$ \\ \bottomrule
\end{tabularx}
\end{table}
如果只想復制算法顯示,則一個表可能就足夠了:
\documentclass{article}
\usepackage{float,tabularx,booktabs,amsmath,mleftright}
\usepackage{lipsum}
\begin{document}
\sloppy % Just for this example
\lipsum[1]
\begin{table}[H]
\begin{tabularx}{\textwidth}{ @{} X @{} }
\toprule
\textbf{Algorithm 2:} The Forward algorithm \\
\midrule
\textbf{Initialization:} \\
\ $\alpha_1(i) = \pi_i b_i(O_1), \ 1 \leq i \leq K$ \\
\\
\textbf{Recursion:} \\
\textbf{for} $t = 1, \dots, T - 1$ \textbf{do} \\
\begin{tabular}{ @{\hspace{\tabcolsep}} | l }
\textbf{for} $j = 1, \dots, K$ \textbf{do} \\
\begin{tabular}{ @{\hspace{\tabcolsep}} | l }
$\displaystyle \alpha_{t + 1}(j) = \mleft[ \sum_{i = 1}^k \alpha_t (i) \alpha_{i j} \mright] b_j(O_{t + 1})$ \\
\end{tabular} \\
\textbf{end}
\end{tabular} \\
\textbf{end} \\
\\
\textbf{Result:} $\displaystyle P(O_{1:T}) = \sum_{i = 1}^N \alpha_T(i)$ \\
\bottomrule
\end{tabularx}
\end{table}
\lipsum[2]
\end{document}
一些注意事項:
使用[H]
ere浮點說明符可以使算法的位置與代碼保持一致。 這有效地消除了浮動功能。 需要float
包 。
tabularx
使用X
列將表格拉伸到指定寬度。 還使用@{}
刪除X
列周圍的空間,以使算法與列邊緣齊平。
booktabs
提供了線條和垂直間距的整齊布局。
amsmath
的\\dots
提供了最佳的間距各地\\dots
,取決於它在使用的實例。避免使用...
來表示橢圓。
通過\\displaystyle
可以在數學樣式的文本樣式使用中擴展顯示運算符。 它確實會延長線的高度。
mleftright
的\\mleft
... \\mright
對在定界符周圍提供了比傳統\\left
... \\right
更好的間距。
垂直規則源自使用自然列寬度和寬度\\tabcolsep
的強制縮進的嵌套tabular
s。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.