tabularx-table 的位置

tabularx-table 的位置

我正在尝试制作一个横向文档,其中包含 3 列中的几个(假)条形码。数据在表格中。现在的问题是,在第二列中,表格为其节标题留下了大量空间——我似乎无法修复该位置。

这是我的 MWE:

\documentclass{report}
\usepackage
[
        a4paper,% other options: a3paper, a5paper, etc
        landscape,
        left=1cm,
        right=2cm,
        top=1cm,
        bottom=1cm,
        % use vmargin=2cm to make vertical margins equal to 2cm.
        % us  hmargin=3cm to make horizontal margins equal to 3cm.
        % use margin=3cm to make all margins  equal to 3cm.
]
{geometry}
\usepackage{multicol}
\usepackage{tabularx}
\setlength{\extrarowheight}{20pt}
\usepackage{lipsum}

\usepackage{float}
\restylefloat{table}


\def\barcode#1#2#3#4#5#6#7{\begingroup%
  \dimen0=0.1em
  \def\stack##1##2{\oalign{##1\cr\hidewidth##2\hidewidth}}%
  \def\0##1{\kern##1\dimen0}%
  \def\1##1{\vrule height5ex width##1\dimen0}%
  \def\L##1{\ifcase##1\bc3211##1\or\bc2221##1\or\bc2122##1\or\bc1411##1%
    \or\bc1132##1\or\bc1231##1\or\bc1114##1\or\bc1312##1\or\bc1213##1%
    \or\bc3112##1\fi}%
  \def\R##1{\bgroup\let\next\1\let\1\0\let\0\next\L##1\egroup}%
  \def\G##1{\bgroup\let\bc\bcg\L##1\egroup}% reverse
  \def\bc##1##2##3##4##5{\stack{\0##1\1##2\0##3\1##4}##5}%
  \def\bcg##1##2##3##4##5{\stack{\0##4\1##3\0##2\1##1}##5}%
  \def\bcR##1##2##3##4##5##6{\R##1\R##2\R##3\R##4\R##5\R##6\11\01\11\09%
    \endgroup}%
  \stack{\09}#1\11\01\11\L#2%
  \ifcase#1\L#3\L#4\L#5\L#6\L#7\or\L#3\G#4\L#5\G#6\G#7%
    \or\L#3\G#4\G#5\L#6\G#7\or\L#3\G#4\G#5\G#6\L#7%
    \or\G#3\L#4\L#5\G#6\G#7\or\G#3\G#4\L#5\L#6\G#7%
    \or\G#3\G#4\G#5\L#6\L#7\or\G#3\L#4\G#5\L#6\G#7%
    \or\G#3\L#4\G#5\G#6\L#7\or\G#3\G#4\L#5\G#6\L#7%
  \fi\01\11\01\11\01\bcR}

\begin{document}

\section*{Virtuelles Lager - \"Ubersicht Barcodes}
\begin{multicols}{3}
\subsection*{CPU}
\begin{tabularx}{\linewidth}{|X|c|}
\hline
MacBook 12"                 & \barcode 8793462789110 \\\hline
MacBook Air 11"         & \barcode 8793462789111 \\\hline
MacBook Air 13"             & \barcode 8793462789112 \\\hline
MacBook Pro 13"         & \barcode 8793462789113 \\\hline
MacBook Pro 15"         & \barcode 8793462789114 \\\hline
iMac 21"                        & \barcode 8793462789115 \\\hline
iMac 27"                        & \barcode 8793462789116 \\\hline
iMac Pro                        & \barcode 8793462789117 \\\hline
Mac Pro                     & \barcode 8793462789118 \\\hline
\end{tabularx}
\columnbreak

\subsection*{iOS}
\begin{tabularx}{\linewidth}{|X|c|}
\hline
iPad 9.7"                           & \barcode 8793462789120 \\\hline
iPad Pro 10.5"                  & \barcode 8793462789121 \\\hline
iPad    Pro 12.9"                   & \barcode 8793462789122 \\\hline
iPhone SE                       & \barcode 8793462789123 \\\hline
iPhone 8                            & \barcode 8793462789124 \\\hline
iPhone 8 Plus                   & \barcode 8793462789125 \\\hline
iPhone X                            & \barcode 8793462789126  \\\hline
\end{tabularx}
\columnbreak

\subsection*{Zubeh\"or}
%\begin{table}    % Embedding to table env results in not showing the tabularx at all...
\begin{tabularx}{\linewidth}[!H]{|X|c|}
\hline
iPhone X Case  & \barcode 8793462789130\\\hline
\end{tabularx}
%\end{table}

\end{multicols}
\end{document}

结果如下:

在此处输入图片描述

我怎样才能实现这个目标?

答案1

打破之前填充列:

\documentclass{report}
\usepackage[
  a4paper,% other options: a3paper, a5paper, etc
  landscape,
  left=1cm,
  right=2cm,
  top=1cm,
  bottom=1cm,
  % use vmargin=2cm to make vertical margins equal to 2cm.
  % us  hmargin=3cm to make horizontal margins equal to 3cm.
  % use margin=3cm to make all margins  equal to 3cm.
]{geometry}
\usepackage{multicol}
\usepackage{tabularx}
\usepackage{lipsum}

\usepackage{float}
\restylefloat{table}

\setlength{\extrarowheight}{20pt}

\def\barcode#1#2#3#4#5#6#7{\begingroup%
  \dimen0=0.1em
  \def\stack##1##2{\oalign{##1\cr\hidewidth##2\hidewidth}}%
  \def\0##1{\kern##1\dimen0}%
  \def\1##1{\vrule height5ex width##1\dimen0}%
  \def\L##1{\ifcase##1\bc3211##1\or\bc2221##1\or\bc2122##1\or\bc1411##1%
    \or\bc1132##1\or\bc1231##1\or\bc1114##1\or\bc1312##1\or\bc1213##1%
    \or\bc3112##1\fi}%
  \def\R##1{\bgroup\let\next\1\let\1\0\let\0\next\L##1\egroup}%
  \def\G##1{\bgroup\let\bc\bcg\L##1\egroup}% reverse
  \def\bc##1##2##3##4##5{\stack{\0##1\1##2\0##3\1##4}##5}%
  \def\bcg##1##2##3##4##5{\stack{\0##4\1##3\0##2\1##1}##5}%
  \def\bcR##1##2##3##4##5##6{\R##1\R##2\R##3\R##4\R##5\R##6\11\01\11\09%
    \endgroup}%
  \stack{\09}#1\11\01\11\L#2%
  \ifcase#1\L#3\L#4\L#5\L#6\L#7\or\L#3\G#4\L#5\G#6\G#7%
    \or\L#3\G#4\G#5\L#6\G#7\or\L#3\G#4\G#5\G#6\L#7%
    \or\G#3\L#4\L#5\G#6\G#7\or\G#3\G#4\L#5\L#6\G#7%
    \or\G#3\G#4\G#5\L#6\L#7\or\G#3\L#4\G#5\L#6\G#7%
    \or\G#3\L#4\G#5\G#6\L#7\or\G#3\G#4\L#5\G#6\L#7%
  \fi\01\11\01\11\01\bcR}

\begin{document}

\section*{Virtuelles Lager - \"Ubersicht Barcodes}
\begin{multicols}{3}
\subsection*{CPU}

\begin{tabularx}{\linewidth}{|X|c|}
\hline
MacBook 12"       & \barcode 8793462789110 \\\hline
MacBook Air 11"   & \barcode 8793462789111 \\\hline
MacBook Air 13"   & \barcode 8793462789112 \\\hline
MacBook Pro 13"   & \barcode 8793462789113 \\\hline
MacBook Pro 15"   & \barcode 8793462789114 \\\hline
iMac 21"          & \barcode 8793462789115 \\\hline
iMac 27"          & \barcode 8793462789116 \\\hline
iMac Pro          & \barcode 8793462789117 \\\hline
Mac Pro           & \barcode 8793462789118 \\\hline
\end{tabularx}

\vspace*{\fill}
\columnbreak

\subsection*{iOS}
\begin{tabularx}{\linewidth}{|X|c|}
\hline
iPad 9.7"         & \barcode 8793462789120 \\\hline
iPad Pro 10.5"    & \barcode 8793462789121 \\\hline
iPad    Pro 12.9" & \barcode 8793462789122 \\\hline
iPhone SE         & \barcode 8793462789123 \\\hline
iPhone 8          & \barcode 8793462789124 \\\hline
iPhone 8 Plus     & \barcode 8793462789125 \\\hline
iPhone X          & \barcode 8793462789126  \\\hline
\end{tabularx}

\vspace*{\fill}
\columnbreak

\subsection*{Zubeh\"or}
\begin{tabularx}{\linewidth}[!H]{|X|c|}
\hline
iPhone X Case  & \barcode 8793462789130\\\hline
\end{tabularx}

\vspace*{\fill}

\end{multicols}
\end{document}

在此处输入图片描述

答案2

multicol尝试平衡列。因此,子部分标题和表格之间的可拉伸空间被拉伸以填充页面。可以通过以下方式关闭平衡\raggedcolumns

\usepackage{multicol}
\raggedcolumns

结果

答案3

除了该multicol包之外,您还可以使用paracol允许具有“同步”列的多列文档的包。

应用到您的示例中,您只需分别替换\usepackage{multicol}by \usepackage{paracol}\begin{multicols}{3}by\begin{paracol}{3}\columnbreakby \swithcolumn

\documentclass{report}
\usepackage
[
        a4paper,% other options: a3paper, a5paper, etc
        landscape,
        left=1cm,
        right=2cm,
        top=1cm,
        bottom=1cm,
        % use vmargin=2cm to make vertical margins equal to 2cm.
        % us  hmargin=3cm to make horizontal margins equal to 3cm.
        % use margin=3cm to make all margins  equal to 3cm.
]
{geometry}

\usepackage{tabularx}
\setlength{\extrarowheight}{20pt}

%\usepackage[utf8]{inputenc} %<------------

\usepackage{paracol}%<--------------

\usepackage{float}
\restylefloat{table}


\def\barcode#1#2#3#4#5#6#7{\begingroup%
  \dimen0=0.1em
  \def\stack##1##2{\oalign{##1\cr\hidewidth##2\hidewidth}}%
  \def\0##1{\kern##1\dimen0}%
  \def\1##1{\vrule height5ex width##1\dimen0}%
  \def\L##1{\ifcase##1\bc3211##1\or\bc2221##1\or\bc2122##1\or\bc1411##1%
    \or\bc1132##1\or\bc1231##1\or\bc1114##1\or\bc1312##1\or\bc1213##1%
    \or\bc3112##1\fi}%
  \def\R##1{\bgroup\let\next\1\let\1\0\let\0\next\L##1\egroup}%
  \def\G##1{\bgroup\let\bc\bcg\L##1\egroup}% reverse
  \def\bc##1##2##3##4##5{\stack{\0##1\1##2\0##3\1##4}##5}%
  \def\bcg##1##2##3##4##5{\stack{\0##4\1##3\0##2\1##1}##5}%
  \def\bcR##1##2##3##4##5##6{\R##1\R##2\R##3\R##4\R##5\R##6\11\01\11\09%
    \endgroup}%
  \stack{\09}#1\11\01\11\L#2%
  \ifcase#1\L#3\L#4\L#5\L#6\L#7\or\L#3\G#4\L#5\G#6\G#7%
    \or\L#3\G#4\G#5\L#6\G#7\or\L#3\G#4\G#5\G#6\L#7%
    \or\G#3\L#4\L#5\G#6\G#7\or\G#3\G#4\L#5\L#6\G#7%
    \or\G#3\G#4\G#5\L#6\L#7\or\G#3\L#4\G#5\L#6\G#7%
    \or\G#3\L#4\G#5\G#6\L#7\or\G#3\G#4\L#5\G#6\L#7%
  \fi\01\11\01\11\01\bcR}

\begin{document}

%\pagestyle{empty} %<-----------------
\section*{Virtuelles Lager - Übersicht Barcodes}
\begin{paracol}{3}%<-----------
\subsection*{CPU}

\begin{tabularx}{\linewidth}{|X|c|}
\hline
MacBook 12"                 & \barcode 8793462789110 \\\hline
MacBook Air 11"         & \barcode 8793462789111 \\\hline
MacBook Air 13"             & \barcode 8793462789112 \\\hline
MacBook Pro 13"         & \barcode 8793462789113 \\\hline
MacBook Pro 15"         & \barcode 8793462789114 \\\hline
iMac 21"                        & \barcode 8793462789115 \\\hline
iMac 27"                        & \barcode 8793462789116 \\\hline
iMac Pro                        & \barcode 8793462789117 \\\hline
Mac Pro                     & \barcode 8793462789118 \\\hline
\end{tabularx}

\switchcolumn %<--------------

\subsection*{iOS}
\begin{tabularx}{\linewidth}{|X|c|}
\hline
iPad 9.7"                           & \barcode 8793462789120 \\\hline
iPad Pro 10.5"                  & \barcode 8793462789121 \\\hline
iPad    Pro 12.9"                   & \barcode 8793462789122 \\\hline
iPhone SE                       & \barcode 8793462789123 \\\hline
iPhone 8                            & \barcode 8793462789124 \\\hline
iPhone 8 Plus                   & \barcode 8793462789125 \\\hline
iPhone X                            & \barcode 8793462789126  \\\hline
\end{tabularx}

\switchcolumn %<----------------


\subsection*{Zubehör}
\begin{tabularx}{\linewidth}[!H]{|X|c|}
\hline
iPhone X Case  & \barcode 8793462789130\\\hline
\end{tabularx}

\end{paracol} %<----------------
\end{document}

我还\"UÜ和替换\"oö。在 2018 版 LaTeX 中,UTF-8 是新的默认输入编码,可让您直接输入变音符号。在旧版本中,您需要 才能\usepackage[utf8]{inputenc}编译上述示例。

由于您大幅减少了页面底部边距,您可能注意到页码几乎被截断。如果您不想对页面进行编号,可以使用\pagestyle{empty}示例中所示的方法。

在此处输入图片描述

答案4

使用单个tabularxand就简单多了hhline

\documentclass{report}
\usepackage
[ a4paper,% other options: a3paper, a5paper, etc
        landscape,
        left=1cm,
        right=2cm,
        top=1cm,
        bottom=1cm,
        % use vmargin=2cm to make vertical margins equal to 2cm.
        % us hmargin=3cm to make horizontal margins equal to 3cm.
        % use margin=3cm to make all margins equal to 3cm.
]
{geometry}
\usepackage{tabularx}
\setlength{\extrarowheight}{20pt}
\usepackage{lipsum}

\usepackage{float}
\restylefloat{table}

\def\barcode#1#2#3#4#5#6#7{\begingroup%
  \dimen0=0.1em
  \def\stack##1##2{\oalign{##1\cr\hidewidth##2\hidewidth}}%
  \def\0##1{\kern##1\dimen0}%
  \def\1##1{\vrule height5ex width##1\dimen0}%
  \def\L##1{\ifcase##1\bc3211##1\or\bc2221##1\or\bc2122##1\or\bc1411##1%
    \or\bc1132##1\or\bc1231##1\or\bc1114##1\or\bc1312##1\or\bc1213##1%
    \or\bc3112##1\fi}%
  \def\R##1{\bgroup\let\next\1\let\1\0\let\0\next\L##1\egroup}%
  \def\G##1{\bgroup\let\bc\bcg\L##1\egroup}% reverse
  \def\bc##1##2##3##4##5{\stack{\0##1\1##2\0##3\1##4}##5}%
  \def\bcg##1##2##3##4##5{\stack{\0##4\1##3\0##2\1##1}##5}%
  \def\bcR##1##2##3##4##5##6{\R##1\R##2\R##3\R##4\R##5\R##6\11\01\11\09%
    \endgroup}%
  \stack{\09}#1\11\01\11\L#2%
  \ifcase#1\L#3\L#4\L#5\L#6\L#7\or\L#3\G#4\L#5\G#6\G#7%
    \or\L#3\G#4\G#5\L#6\G#7\or\L#3\G#4\G#5\G#6\L#7%
    \or\G#3\L#4\L#5\G#6\G#7\or\G#3\G#4\L#5\L#6\G#7%
    \or\G#3\G#4\G#5\L#6\L#7\or\G#3\L#4\G#5\L#6\G#7%
    \or\G#3\L#4\G#5\G#6\L#7\or\G#3\G#4\L#5\G#6\L#7%
  \fi\01\11\01\11\01\bcR}
\usepackage{hhline}

\begin{document}

\section*{Virtuelles Lager - \"Ubersicht Barcodes}

\begin{tabularx}{\linewidth}{|X|c|c|X|c|c|X|c|}
\multicolumn{2}{@{}l}{\large\bfseries CPU} & \multicolumn{1}{p{5mm}}{} & \multicolumn{2}{@{}l}{\large\bfseries iOS} & \multicolumn{1}{p{5mm}}{} & \multicolumn{2}{@{}l}{\large\bfseries Zubehör}\\[1ex]
\hhline{|--|~|--|~|--|}
MacBook 12" & \barcode 8793462789110 & & iPad 9.7" & \barcode 8793462789120 & & iPhone X Case & \barcode 8793462789130\\
\hhline{|--|~|--|~--|}
MacBook Air 11" & \barcode 8793462789111 & & iPad Pro 10.5" & \barcode 8793462789121 & \multicolumn{3}{c}{}\\
\hhline{|--|~|--|~~~}
MacBook Air 13" & \barcode 8793462789112 & & iPad Pro 12.9" & \barcode 8793462789122 \\
\hhline{|--|~|--|~~~}
MacBook Pro 13" & \barcode 8793462789113 & & iPhone SE & \barcode 8793462789123 \\
\hhline{|--|~|--|~~~}
MacBook Pro 15" & \barcode 8793462789114 & & iPhone 8 & \barcode 8793462789124 \\
\hhline{|--|~|--|~~~}
iMac 21" & \barcode 8793462789115 & & iPhone 8 Plus & \barcode 8793462789125 \\
\hhline{|--|~|--|~~~}
iMac 27" & \barcode 8793462789116 & & iPhone X & \barcode 8793462789126 \\
\hhline{|--|~|--|~~~}
iMac Pro & \barcode 8793462789117 \\
\hhline{|--|*6~}
Mac Pro & \barcode 8793462789118 \\
\hhline{|--|*6~}
\end{tabularx}

\end{document} 

在此处输入图片描述

相关内容