自动在文本中显示两列

自动在文本中显示两列

我写过多个单页文档。句子主要由逐项列表组成。当书面文字超过一页长度并流入另一页时,我会通过更改序言将它们转换为两列。这涉及每次编译文档后返回源代码。我可以使用两列作为所有文档的默认设置,但对于适合单列的短文档,它看起来很奇怪。有没有办法可以自动执行此操作?每当文档长度超过页面长度时,它应该更改为两列而不是一列。

这是 MWE

  % Created 2019-01-21 Mon 11:20
% Intended LaTeX compiler: xelatex
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\pagenumbering{}
\usepackage[a4paper, top=42mm, right=2cm, bottom=1.5cm]{geometry}
\usepackage{fontspec,xltxtra}
\usepackage{polyglossia}
\usepackage[Latin,Devanagari]{ucharclasses}
\setmainfont{Arial Unicode MS}
\setlength{\parindent}{0pt}
\author{Me}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={Me},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 25.3.1 (Org mode 9.1.14)}, 
 pdflang={English}}
\begin{document}

Mr X Y Z 

DOB XX XX 196X

Phone 982640xxxx


\today 


\section*{Past History}
\label{sec:orgdd28594}
\begin{itemize}
\item Idiopathic ulcerative colitis (proctosigmoiditis) 2013
\end{itemize}
\section*{Follow up}
\label{sec:orgb1e6798}
Stool frequency of 4-6 per day, Painful. Bleeding separate from stools. 
Bloating of abdomen 
There is no weight loss. 
\section*{Examination}
\label{sec:org1fd6fb7}
No abnormality detected 
\section*{Investigations}
\label{sec:org168a269}
Complete blood count , Random blood sugar, sigmoidoscopy 
SCHEDULED: \textit{<2019-01-23 Wed> } 

\section*{Rx}
\label{sec:org0d9debc}
\begin{enumerate}
\item TAB VEGAZ  OD (MESALAMIN) 1.2 GM   TWICE DAILY (दिन में 2 बार)  AFTER MEALS (खाने के बाद)   X  Long term
\item TAB FOLVITE (FOLIC ACID) 5 MG  ONCE DAILY (दिन में 1 बार )1-0-0-0 X LONG TERM
\item CREMAGEL (DILTIAZEM)  aply at anus after seitz bath twice daily (दिन में 2 बार) 1-0-1-0 x 15 days
\item TORBULK /LACTIFIBER 180 GM दो चम्मच पावडर  एक  गिलास पानी में डाल कर शाम को ले  (सोते समय)   0-0-0-1 X 15 days
\item TAB CROCIN (PARACETAMOL) 500 MG 1 TABLET   as and when needed (जब जरुरत हो तो दवा ले ) FOR FEVER OR PAIN
\item LIGNOX (LIGNOCAIN) GEL before and after defecation if severe anal pain
\end{enumerate}
\end{document}

答案1

您的示例没有显示任何使用编号的引用或分段单元。此外,没有明确使用hyperref。所以,下面我删除了这些元素。

最后,单列和双列布局的内容布局非常不同。以最初的“墓碑”信息为例。它主要包含在单列文档的左半部分。如果需要切换到双列文档,则上半部分的右侧会突然被利用,对于刚好滚动到两页的文档,切换到双列布局可以使其适合单页。

该解决方案的主要方法是将整个文档内容包装到oneortwocolumn宏中。

在此处输入图片描述

\documentclass{article}

\usepackage{xparse}% Unless you have an updated LaTeX (as of Oct 2020)

\newsavebox{\ONEorTWOcol}
\NewDocumentCommand{\oneortwocolumn}{s +m}{%
  \IfBooleanTF{#1}{%
    #2%
  }{%
    % Store the entire document in a box that one can extract measurements from
    \begin{lrbox}{\ONEorTWOcol}%
      \begin{minipage}[b]{\textwidth}
        #2%
      \end{minipage}
    \end{lrbox}
    
    % Check if box is taller than \textheight
    \ifdim\ht\ONEorTWOcol>\textheight
      % If so, reset the entire document in a two-column document
      \begin{multicols}{2}
        #2%
      \end{multicols}
    \else
      % Otherwise, reset it in its original form
      #2%
    \fi
  }
}

\usepackage{multicol,lipsum}
\usepackage[a4paper, top=42mm, right=2cm, bottom=1.5cm]{geometry}

\setlength{\parindent}{0pt}

\begin{document}

\oneortwocolumn{

Mr Random Randofsky

DOB 01-23-4567

Phone 123-456-7890

\today

\section*{Past History}
\begin{itemize}
  \item Idiopathic ulcerative colitis (proctosigmoiditis) 2013
\end{itemize}

\section*{Follow up}
Stool frequency of 4-6 per day, Painful. Bleeding separate from stools.
Bloating of abdomen.
There is no weight loss.

\section*{Examination}
No abnormality detected

\section*{Investigations}
Complete blood count, Random blood sugar, sigmoidoscopy
SCHEDULED: 2019-01-23 Wed

% Check with \lipsum[1-5], which will be set in two-column mode on 1 page
\lipsum[1-10]

\section*{Rx}
\begin{enumerate}
  \item First item
  \item Second item
  \item Third item
  \item Fourth item
  \item Fifth item
  \item Final item
\end{enumerate}

}

\end{document}

如果将随机文本切换为\lipsum[1-5],您会发现它将页面设置为单页上的两列。这是因为丢失的“墓碑”空间突然在双列设置下被占用。如果此切换导致设置不理想,请使用 的星号形式\oneortwocolumn*,这将强制输出为单列布局。

如果需要的话,可以扩展该方法以适应\ref不同情况。

相关内容