在整个文档中保留 longtabu 设置

在整个文档中保留 longtabu 设置

这个问题是上一个问题的延续longtabu 的相同实例

我想创建一个环境,在这个环境中,longtabu为第二个环境实例确定的列宽将在整个文档中使用。David Carlisle 在上一篇文章中给出了一个很好的解决方案 -

\documentclass{article}

\usepackage{longtable,tabu}

\newenvironment{listazo}{
\begin{longtabu} to \textwidth{X[-1l]X}}
{\end{longtabu}}

\makeatletter
\AtBeginDocument{%
{\let\ifhmode\iftrue
\xdef\tmp{\csname LT@ii\endcsname}%
\xdef\tmp{\expandafter\@gobble\tmp}}%
}
\makeatother

\begin{document}


\section*{First}
\begin{listazo}

  side note1 & here is the text and details\\\tmp\kill

\end{listazo}

\section*{Second}
\begin{listazo}

  side note 2 & more text and details over here - bbbbbbbb bbbbb bbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\
  longer side note & bbbb bbb bbb bbb bb bb bb  bb b b b b b b bbbb bbb bbb bbb bb bb bb  bb b b b b b b 

\end{listazo}

\end{document}

结果正如我所愿。但是,如果我将对齐设置更改为longtabu右对齐,如下所示 -

\newenvironment{listazo}{
\begin{longtabu} to \textwidth{X[-1r]X}}  % changed 'l' for 'r' here
{\end{longtabu}}

第一个表格的第一列仍然像这样左对齐(注意:添加 \hfill 并没有解决这个问题)

在此处输入图片描述

非常感谢您的帮助 - 我对此束手无策。

干杯

答案1

哦,这次稍微脆弱一些,但是

在此处输入图片描述

\documentclass{article}

\usepackage{longtable,tabu}

\newenvironment{listazo}{
\begin{longtabu} to \textwidth{X[-1r]X}}
{\end{longtabu}}

\makeatletter
\AtBeginDocument{%
{\let\ifhmode\iftrue\def\omit{\noindent}%
\xdef\tmp{\csname LT@ii\endcsname}%
\xdef\tmp{\expandafter\@gobble\tmp}}%
}
\makeatother

\begin{document}



\section*{First}
\begin{listazo}
  side note1 & here is the text and details\\\tmp\kill
\end{listazo}

\section*{Second}
\begin{listazo}

  side note 2 & more text and details over here - bbbbbbbb bbbbb bbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\
  longer side note & bbbb bbb bbb bbb bb bb bb  bb b b b b b b bbbb bbb bbb bbb bb bb bb  bb b b b b b b 

\end{listazo}


\section*{test}
\begin{listazo}

  side note1 & here is the text and details\\

  side note 2 & more text and details over here - bbbbbbbb bbbbb bbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\
  longer side note & bbbb bbb bbb bbb bb bb bb  bb b b b b b b bbbb bbb bbb bbb bb bb bb  bb b b b b b b 

\end{listazo}


\end{document}

相关内容