如何排版命令行界面命令的输出

如何排版命令行界面命令的输出

我想将以下几行(包括空格)打印到我的 latex 文档中。但这些空格当然总是有问题:

Name: SD
Type: SDHC/SDXC
Speed: default speed
Size: 7691MB
CSD: ver=1, sector_size=512, capacity=15751168 read_bl_len=9
SCR: sd_spec=2, bus_width=5
  sector  | count | align | size(kB)  | wr_time(ms) | wr_speed(MB/s)  |  rd_time(ms)  | rd_speed(MB/s)
        0 |    1  |   4   |     0.5   |     2.38    |       0.21      |      0.56     |      0.87
        0 |    4  |   4   |     2.0   |     2.76    |       0.71      |      1.33     |      1.47
        1 |   16  |   4   |     8.0   |     5.09    |       1.53      |      3.79     |      2.06
       16 |   32  |   4   |    16.0   |     8.94    |       1.75      |      7.09     |      2.21
       48 |   64  |   4   |    32.0   |    15.58    |       2.01      |     13.66     |      2.29
      128 |  128  |   4   |    64.0   |    27.73    |       2.25      |     26.87     |      2.33
 15751104 |   32  |   4   |    16.0   |     7.87    |       1.98      |      7.09     |      2.20
 15751104 |   64  |   4   |    32.0   |    14.44    |       2.16      |     13.67     |      2.29
 15751160 |    1  |   4   |     0.5   |     2.30    |       0.21      |      0.58     |      0.84
  7875584 |    1  |   4   |     0.5   |     2.29    |       0.21      |      0.58     |      0.84
  7875584 |    4  |   4   |     2.0   |     2.76    |       0.71      |      1.33     |      1.46
  7875584 |    8  |   4   |     4.0   |     3.51    |       1.11      |      2.16     |      1.81
  7875584 |   16  |   4   |     8.0   |     5.25    |       1.49      |      3.81     |      2.05
  7875584 |   32  |   4   |    16.0   |     7.79    |       2.01      |      7.09     |      2.20
  7875584 |   64  |   4   |    32.0   |    14.44    |       2.16      |     13.67     |      2.29
  7875584 |  128  |   4   |    64.0   |    41.28    |       1.51      |     26.88     |      2.33
  7875584 |    1  |   1   |     0.5   |     2.18    |       0.22      |      0.59     |      0.83
  7875584 |    8  |   1   |     4.0   |    13.29    |       0.29      |      4.57     |      0.86
  7875584 |  128  |   1   |    64.0   |   213.76    |       0.29      |     73.11     |      0.85

我该怎么做?我不想截取这个东西的屏幕截图。

我说的是那些空间(可见):

··sector··|·count·|·align·|·size(kB)··|·wr_time(ms)·|·wr_speed(MB/s)··|·rd_time(ms)··|·rd_speed(MB/s)
········0 |····1··|···4···|·····0.5···|·····2.38····|······0.21······|······0.56·····|······0.87

答案1

verbatim环境默认可用。根据您的页面布局,您可能不需要将字体大小减小太多。

\documentclass{article}
\begin{document}
{\tiny % reduce font size
\begin{verbatim}
Name: SD
Type: SDHC/SDXC
Speed: default speed
Size: 7691MB
CSD: ver=1, sector_size=512, capacity=15751168 read_bl_len=9
SCR: sd_spec=2, bus_width=5
  sector  | count | align | size(kB)  | wr_time(ms) | wr_speed(MB/s)  |  rd_time(ms)  | rd_speed(MB/s)
        0 |    1  |   4   |     0.5   |     2.38    |       0.21      |      0.56     |      0.87
        0 |    4  |   4   |     2.0   |     2.76    |       0.71      |      1.33     |      1.47
        1 |   16  |   4   |     8.0   |     5.09    |       1.53      |      3.79     |      2.06
       16 |   32  |   4   |    16.0   |     8.94    |       1.75      |      7.09     |      2.21
       48 |   64  |   4   |    32.0   |    15.58    |       2.01      |     13.66     |      2.29
      128 |  128  |   4   |    64.0   |    27.73    |       2.25      |     26.87     |      2.33
 15751104 |   32  |   4   |    16.0   |     7.87    |       1.98      |      7.09     |      2.20
 15751104 |   64  |   4   |    32.0   |    14.44    |       2.16      |     13.67     |      2.29
 15751160 |    1  |   4   |     0.5   |     2.30    |       0.21      |      0.58     |      0.84
  7875584 |    1  |   4   |     0.5   |     2.29    |       0.21      |      0.58     |      0.84
  7875584 |    4  |   4   |     2.0   |     2.76    |       0.71      |      1.33     |      1.46
  7875584 |    8  |   4   |     4.0   |     3.51    |       1.11      |      2.16     |      1.81
  7875584 |   16  |   4   |     8.0   |     5.25    |       1.49      |      3.81     |      2.05
  7875584 |   32  |   4   |    16.0   |     7.79    |       2.01      |      7.09     |      2.20
  7875584 |   64  |   4   |    32.0   |    14.44    |       2.16      |     13.67     |      2.29
  7875584 |  128  |   4   |    64.0   |    41.28    |       1.51      |     26.88     |      2.33
  7875584 |    1  |   1   |     0.5   |     2.18    |       0.22      |      0.59     |      0.83
  7875584 |    8  |   1   |     4.0   |    13.29    |       0.29      |      4.57     |      0.86
  7875584 |  128  |   1   |    64.0   |   213.76    |       0.29      |     73.11     |      0.85
\end{verbatim}
}% end of font size change
\end{document}

答案2

这是一个起点listings

\documentclass{standalone}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=bash]
Name: SD
Type: SDHC/SDXC
Speed: default speed
Size: 7691MB
CSD: ver=1, sector_size=512, capacity=15751168 read_bl_len=9
SCR: sd_spec=2, bus_width=5
 sector  | count | align | size(kB)  | wr_time(ms) | wr_speed(MB/s)  |  rd_time(ms)  | rd_speed(MB/s)
       0 |    1  |   4   |     0.5   |     2.38    |       0.21      |      0.56     |      0.87
       0 |    4  |   4   |     2.0   |     2.76    |       0.71      |      1.33     |      1.47
       1 |   16  |   4   |     8.0   |     5.09    |       1.53      |      3.79     |      2.06
      16 |   32  |   4   |    16.0   |     8.94    |       1.75      |      7.09     |      2.21
      48 |   64  |   4   |    32.0   |    15.58    |       2.01      |     13.66     |      2.29
     128 |  128  |   4   |    64.0   |    27.73    |       2.25      |     26.87     |      2.33
15751104 |   32  |   4   |    16.0   |     7.87    |       1.98      |      7.09     |      2.20
15751104 |   64  |   4   |    32.0   |    14.44    |       2.16      |     13.67     |      2.29
15751160 |    1  |   4   |     0.5   |     2.30    |       0.21      |      0.58     |      0.84
 7875584 |    1  |   4   |     0.5   |     2.29    |       0.21      |      0.58     |      0.84
 7875584 |    4  |   4   |     2.0   |     2.76    |       0.71      |      1.33     |      1.46
 7875584 |    8  |   4   |     4.0   |     3.51    |       1.11      |      2.16     |      1.81
 7875584 |   16  |   4   |     8.0   |     5.25    |       1.49      |      3.81     |      2.05
 7875584 |   32  |   4   |    16.0   |     7.79    |       2.01      |      7.09     |      2.20
 7875584 |   64  |   4   |    32.0   |    14.44    |       2.16      |     13.67     |      2.29
 7875584 |  128  |   4   |    64.0   |    41.28    |       1.51      |     26.88     |      2.33
 7875584 |    1  |   1   |     0.5   |     2.18    |       0.22      |      0.59     |      0.83
 7875584 |    8  |   1   |     4.0   |    13.29    |       0.29      |      4.57     |      0.86
 7875584 |  128  |   1   |    64.0   |   213.76    |       0.29      |     73.11     |      0.85
\end{lstlisting}
\end{document}

然后您可以使用该命令按照您喜欢的格式格式化输出\lstset{}

答案3

您可以调整几个参数,但这是一个起点。

\documentclass{article}
\usepackage{siunitx,booktabs}

\begin{document}

\begin{table}
\centering

\begin{tabular}{
  @{}
  S[table-format=8.0]
  S[table-format=3.0]
  S[table-format=1.0]
  S[table-format=2.1]
  S[table-format=3.2]
  S[table-format=1.2]
  S[table-format=2.2]
  S[table-format=1.2]
  @{}
}
\multicolumn{8}{l}{Name: SD} \\
\multicolumn{8}{l}{Type: SDHC/SDXC} \\
\multicolumn{8}{l}{Speed: default speed} \\
\multicolumn{8}{l}{Size: \SI{7691}{MB}} \\
\multicolumn{8}{l}{CSD: ver=1, sector\_size = 512, capacity = \num{15751168}, read\_bl\_len = 9} \\
\multicolumn{8}{l}{SCR: sd\_spec = 2, bus\_width = 5} \\
\addlinespace
\midrule[\heavyrulewidth]
{sector} & {count} & {align} & {size} & {wr\_time} & {wr\_speed} & {rd\_time}  & {rd\_speed} \\
 & & {(\si{kB})} & {(\si{ms})} & {(\si{ms})} & {(\si{MB/s})} & {(\si{ms})} & {(\si{MB/s})} \\
\midrule
        0 &    1  &   4   &     0.5   &     2.38    &       0.21      &      0.56     &      0.87 \\
        0 &    4  &   4   &     2.0   &     2.76    &       0.71      &      1.33     &      1.47 \\
        1 &   16  &   4   &     8.0   &     5.09    &       1.53      &      3.79     &      2.06 \\
       16 &   32  &   4   &    16.0   &     8.94    &       1.75      &      7.09     &      2.21 \\
       48 &   64  &   4   &    32.0   &    15.58    &       2.01      &     13.66     &      2.29 \\
      128 &  128  &   4   &    64.0   &    27.73    &       2.25      &     26.87     &      2.33 \\
 15751104 &   32  &   4   &    16.0   &     7.87    &       1.98      &      7.09     &      2.20 \\
 15751104 &   64  &   4   &    32.0   &    14.44    &       2.16      &     13.67     &      2.29 \\
 15751160 &    1  &   4   &     0.5   &     2.30    &       0.21      &      0.58     &      0.84 \\
  7875584 &    1  &   4   &     0.5   &     2.29    &       0.21      &      0.58     &      0.84 \\
  7875584 &    4  &   4   &     2.0   &     2.76    &       0.71      &      1.33     &      1.46 \\
  7875584 &    8  &   4   &     4.0   &     3.51    &       1.11      &      2.16     &      1.81 \\
  7875584 &   16  &   4   &     8.0   &     5.25    &       1.49      &      3.81     &      2.05 \\
  7875584 &   32  &   4   &    16.0   &     7.79    &       2.01      &      7.09     &      2.20 \\
  7875584 &   64  &   4   &    32.0   &    14.44    &       2.16      &     13.67     &      2.29 \\
  7875584 &  128  &   4   &    64.0   &    41.28    &       1.51      &     26.88     &      2.33 \\
  7875584 &    1  &   1   &     0.5   &     2.18    &       0.22      &      0.59     &      0.83 \\
  7875584 &    8  &   1   &     4.0   &    13.29    &       0.29      &      4.57     &      0.86 \\
  7875584 &  128  &   1   &    64.0   &   213.76    &       0.29      &     73.11     &      0.85 \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

相关内容