簡體   English   中英

垂直線和寬度表乳膠

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM