
저는 2열 다중 열 환경에서 작업 중이며, Wrapfig를 사용하여 인용문을 생성하려고 합니다. 문제는 이 인용문을 여백에 걸어두고 싶다는 것입니다. 왼쪽 열에 있으면 왼쪽 여백, 오른쪽 열에 있으면 오른쪽 여백입니다.
현재 열 번호를 감지하여 Wrapfig에게 "열 번호 = 1이면 그림을 왼쪽에 매달고, 열 번호 = 2이면 오른쪽에 걸어 두세요"라고 말할 수 있는 방법이 있습니까? 이런 종류의 텍스트가 많아서 이 모든 것을 손으로 설정하는 것은 꽤 지루할 것입니다.
이거 사용해봤는데인용문 패키지, 그러나 지금까지 마이크로타입 오류가 많이 발생했습니다(저는 XeLaTeX를 사용하고 있습니다).
편집: 일종의 MWE는 다음과 같습니다. 분명히 \imaginarycolumnnumberidentifier
제가 추구하는 것입니다. 분명히 이것은 "작동하는" 예제가 아니며 실제로 이전에 etoolbox를 사용해 본 적이 없으므로 이 코드에 다른 문제가 있을 수 있지만 아이디어는 얻을 수 있습니다.
\documentclass{article}
\usepackage{multicol}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{etoolbox}
\newenvironment{pquote}{%
\begin{wrapfigure}[3]{%
\ifnumequal{1}{\imaginarycolumnnumberidentifier}{l}{r}%
}[0.2\columnwith]{0.4\columnwidth}
}{%
\end{wrapfigure}}
\begin{document}
\begin{multicols}{2}
\lipsum[1]
\begin{pquote}
Lorem ipsum!
\end{pquote}
\lipsum[2]
\begin{pquote}
dolor sit amet!
\end{pquote}
\lipsum[3]
\end{multicols}
\end{document}
이미지를 올릴 만큼 평판이 부족하니 출력물을 상상만 하시면 됩니다! 저를 믿으세요. 첫 번째 pquote는 왼쪽에 있고 두 번째 pquote는 오른쪽에 있습니다. 내 마음 속에.
답변1
twocolumn
패키지를 통하지 않고 레이아웃 에 대해 이를 구현하는 방법을 보여 드리겠습니다 multicol
. 이렇게 하면 일부 코딩 문제가 해결됩니다.
\documentclass[twocolumn]{article}
\usepackage{wrapfig}
\usepackage{lipsum}
\makeatletter
\newenvironment{pquote}[1][\relax]{%
\ifx#1\relax\def\@mypl{\if@firstcolumn l\else r\fi}%
\else\def\@mypl{#1}\fi%
\wrapfigure[3]{\@mypl}[0.2\columnwidth]{0.4\columnwidth}%
\large\bfseries}{\par\endwrapfigure}
\makeatother
\begin{document}
\lipsum[1]
\begin{pquote}
Lorem ipsum!
\end{pquote}
\lipsum[2-4]
\begin{pquote}
Dolor sit amet!
\end{pquote}
\lipsum[5-8]
\begin{pquote}[r]
Mauris ut est.
\end{pquote}
\lipsum[9]
\end{document}
불행하게도 사용 pquote
의 변형으로 설정하는 일반적인 방법은 작동하지 않습니다. 고정된 위치를 사용하여 간단한 테스트 문서를 만들어 보면 알 수 있습니다. 이는 인수가 처리되는 방식과 관련이 있습니다. 대신 적절한 인수와 함께 사용하고 . 또한 위치 지정 인수는 허용된 문자열 중 하나로 직접 확장되어야 하므로 이는 중간 매크로를 통해 수행되어야 합니다.wrapfigure
\begin{wrapfigure}
\wrapfigure
\endwrapfigure
이제 위치를 결정하는 데 사용할 수 있는 twocolumn
테스트가 있습니다 . \if@firstcolumn
불행히도 100% 완벽한 것은 아니므로 위의 정의는 위치 지정을 강제할 수 있는 선택적 인수를 제공합니다.
상황은 multicols
좀 더 복잡하고 이를 수행하기 위해 쉽게 접근할 수 있는 변수가 없습니다. 기본적으로 multicol
자료를 하나의 긴 상자에 조판한 다음 각 열의 상단에서 정확한 양을 분할합니다. 열 번호의 개수를 유지하는 내부 변수가 있지만 쉽게 접근할 수는 없습니다. 또한 multicol
주어진 조판 자료를 동일한 높이의 여러 상자로 분할하여 열의 균형을 맞추려고 시도합니다. 조판이 프로세스에서 변경되는 경우 이는 더 복잡합니다. 이에 대한 한 가지 증상은 \marginpar
에서 s가 허용되지 않는다는 것입니다 multicols
(패키지 문서 참조). 반면 twocolumn
여백에서는 pars가 필요에 따라 측면을 훌륭하게 전환하여 (상당히) 작동합니다.
덧셈의견에 대한 응답으로:
사용을 원 multicols
하고 배치를 지정할 준비가 된 경우 코딩은 더 간단하지만 여전히 다음을 피해야 합니다 \begin{wrapfigure}
.
\documentclass{article}
\usepackage{multicol,ragged2e}
\usepackage{wrapfig}
\usepackage{lipsum}
\makeatletter
\newenvironment{pquote}[2]{%
\wrapfigure[#1]{#2}[0.2\columnwidth]{0.4\columnwidth}%
\large\bfseries\Centering}{\par\endwrapfigure}
\makeatother
\begin{document}
\begin{multicols}{2}
\lipsum[1]
\begin{pquote}{4}{l}
Lorem ipsum!
\end{pquote}
\lipsum[2-4]
\begin{pquote}{6}{r}
Dolor sit amet!
\end{pquote}
\lipsum[5-8]
\begin{pquote}{5}{r}
Mauris ut est.
\end{pquote}
\lipsum[9]
\end{multicols}
\end{document}
답변2
Andrew가 그의 답변에서 언급했듯이 조판을 수행하는 동안 "현재" 열이 전혀 알려지지 않았기 때문에 다중 열에 대한 솔루션은 다소 더 복잡합니다. 따라서 여러 조판 실행(파일 사용)을 포함하는 다소 복잡한 접근 방식이 .aux
필요합니다.
\docolaction{left}{middle}{right}
다음은 열 유형에 따라 조건부 코드를 실행하는 솔루션의 첫 번째 초안입니다 . 열 유형이 아직 알려지지 않은 경우 첫 번째 열이 가정됩니다(기본값).
\begin{filecontents}{mccolaction.sty}
%
% \begin{macrocode}
\ProvidesPackage{mccolaction}
[2013/05/05 v0.9b column actions for multicolumn formatting (FMi)]
% \end{macrocode}
%
% \begin{macrocode}
\RequirePackage{etoolbox}
\RequirePackage{multicol}[2011/12/20]
% \end{macrocode}
%
% Determining the current column in multicols is difficult because
% (in contrast to the twocolumn mode of standard LaTeX) the
% multicols columns are determined very late in the game and due to
% the balancing routine it is not known where a piece of text is
% going to end up at the time the text is typeset. Only afterwards,
% when everything has be typeset into a single long galley, that
% galley is split into individual columns (at the very end in a
% possibly huge set of trials to balance the column material.
%
% Therefore the approach taken here is to write out a single line
% into the .aux file whenever a column is finally typeset:
%\begin{verbatim}
% \mc@col@status{<number>}
%\end{verbatim}
% The number in the argument denotes the different kind of column: 1
% for left column 2 for any middle column and 3 for the final column.
%
% We only set this up for the LR typesetting case here, something
% similar could be done for the RL version:
% \begin{macrocode}
\patchcmd{\LR@column@boxes}{\box\count@}
{\protected@write\@auxout{}{\string\mc@col@status
{\ifmc@firstcol 1\else 2\fi}}%
\mc@firstcolfalse
\box\count@}
{\typeout{juhu!}}{\typeout{oje!}}%
\patchcmd{\LR@column@boxes}{\box\mult@rightbox}
{\protected@write\@auxout{}{\string\mc@col@status{3}}%
\box\mult@rightbox}%
{\typeout{juhu!}}{\typeout{oje!}}%
\newif\ifmc@firstcol
\mc@firstcoltrue
% \end{macrocode}
%
% Need to reinitiate \verb=\mc@align@columns= as this was let to
% the old definition of \verb=\LR@column@boxes=.
%
% \begin{macrocode}
\LRmulticolcolumns
% Whenever we want to do something that depends on the current
% column we execute \verb=\docolaction=. This command takes one
% optional and three mandatory arguments. The mandatory ones denote
% what to do if this is a ``left'', ``middle'', or ``right'' column
% and the optional one is simply there to say what to do if we don't
% know (default is to use the ``left'' column action in that case).
%
% We use one counter \verb=\mc@col@check@num= to generate us unique
% label names. Each time we execute \verb=\docolaction= we increment
% this counter to get a new name.
% \begin{macrocode}
\newcount\mc@col@check@num
% \end{macrocode}
% The generated ``labels'' are named
% \verb=\mc@col-\the\mc@col@check@num= and they hold as values the
% numbers 1, 2, or 3 denoting the current column type.
% \begin{macrocode}
\newcommand\docolaction[4][1]{%
\global\advance\mc@col@check@num\@ne
\edef\mc@col@type{\expandafter\ifx
\csname mc@col-\the\mc@col@check@num\endcsname\relax
0\else
\csname mc@col-\the\mc@col@check@num\endcsname
\fi}%
% \end{macrocode}
% We prefix with 0 so that an unknown label (that returns
% \verb=\relax=) will result in case 0
% \begin{macrocode}
\ifcase \mc@col@type\relax
% \end{macrocode}
% If column is unknown we use the default action or the action
% denoted by the optional argument (so that arg can take the value
% 1, 2, 3)
% \begin{macrocode}
\ifcase #1\or #2\or#3\or#4\fi % 0 not known use first col as default
\or
% \end{macrocode}
% Otherwise we know (or think we know) that this is a first, middle,
% or last column:
% \begin{macrocode}
#2% % 1 First col
\or
#3% % 2 any middle col
\or
#4% % 3 last col
\else
\ERROR
\fi
% \end{macrocode}
% But how does the column number get associated with our label? We
% do do this by writing another line into the aux file at this point:
% \begin{macrocode}
\edef\next{\write\@auxout
{\string\mc@set@col@status{mc@col-\the\mc@col@check@num}%
{\mc@col@type}}}%
\next
}
% \end{macrocode}
%
% Because of extra data writing to the aux file the aux file will
% now contain something like the following after the document is
% processed the first time:
%\begin{verbatim}
%\relax
%\mc@col@status{1}
%\mc@set@col@status{lcol-1}{0}
%\mc@col@status{2}
%\mc@set@col@status{lcol-2}{0}
%\mc@col@status{3}
%\mc@set@col@status{lcol-3}{0}
%\mc@col@status{1}
%\mc@col@status{2}
%\mc@col@status{3}
%\mc@set@col@status{lcol-4}{0}
%\end{verbatim}
% The \verb=\mc@col@status= line denotes the column type and has been
% writting out just before corresponding the column box was placed
% onto the page.
% The\verb=\mc@set@col@status= lines have been written out as part
% of shipping the column boxes out, e.g.,
% \verb=\mc@set@col@status{lcol-1}{0}= was therefore somewhere within
% the first column as it appears between \verb=\mc@col@status{1}=
% and \verb=\mc@col@status{2}=
% The second argument in that line is the value used in the previous
% run (or zero if there was no previous run. We can use this to
% determine if a rerun is necessary.
%
% Thus with this knowledge we can set things up to get the labels
% working.
%
% When the aux file is read in \verb=\mc@col@status= is used to set
% \verb=\mc@curr@col@status=:
%
% \begin{macrocode}
\def\mc@col@status#1{\gdef\mc@curr@col@status{#1}}
% \end{macrocode}
% And when \verb=\mc@set@col@status= is executed we can simply set
% up the label by associating it with the \verb=\mc@curr@col@status=
% and ignore the second argument:
% \begin{macrocode}
\def\mc@set@col@status#1#2{%
\global\expandafter\let\csname #1\endcsname\mc@curr@col@status}
% \end{macrocode}
%
% The above definition is being used when the \texttt{.aux} file is
% read in at the beginning. At the end we need a different
% definition to test if another typesetting run is needed. There we
% compare the value used in the current run (stored in the second
% argument) with the value used on the next run. If those two values
% differ we set \verb=@tempswa= to false which will trigger the
% ``Label(s) may have changed'' warning.
% \begin{macrocode}
\AtEndDocument{\def\mc@set@col@status#1#2{%
\ifnum #2=\mc@curr@col@status\else
\@tempswatrue
\fi}%
}
% \end{macrocode}
\end{filecontents}
\documentclass{article}
\usepackage{mccolaction}
\usepackage{wrapfig}
\usepackage{lipsum}
% An application of \docolaction. We put the whole wrapfigure into the
% args so that the internal label used is placed after wrapfigure.
\newcommand\pquote[2]{%
\docolaction
{\begin{wrapfigure}[#1]{l}[0.2\columnwidth]{0.4\columnwidth}%
\raggedright\large\bfseries #2\end{wrapfigure}}%
{\begin{wrapfigure}[#1]{l}[0pt]{0.4\columnwidth}%
\raggedright\large\bfseries #2\end{wrapfigure}}%
{\begin{wrapfigure}[#1]{r}[0.2\columnwidth]{0.4\columnwidth}%
\raggedright\large\bfseries #2\end{wrapfigure}}%
\ignorespaces
}
\setlength\columnseprule{.7pt}
\setlength\emergencystretch{2em}
\begin{document}
\begin{multicols}{3}
\lipsum[1]
\pquote{4}{Lorem ipsum!}
\lipsum[2]
\pquote{5}{Dolor sit amet!}
\lipsum[4-5]
\pquote{4}{Mauris ut est.}
\lipsum[6-7]
Only a few words left \ldots
Here the pquote comes in the middle of the paragraph for a change
\pquote{6}{Final test related to the edge}
as we can see. Only a few words left so this drops off the column \ldots
\end{multicols}
\end{document}
이 파일을 실행하면 다음과 같은 결과를 얻습니다.
\pquote
두 번째 페이지에서는 모든 것이 완벽하지는 않을 것임을 보여 주지만 이 경우에는 의도적으로 끝 부분에 너무 가깝게 배치했기 때문입니다 .
4개의 열을 사용하도록 파일을 변경하면 열에 걸쳐 하나의 랩 그림이 절단되어 결국 두 패키지가 이 문제를 자동으로 해결할 만큼 잘 작동하지 않는 문제가 발생합니다.
요약하자면, 충분히 잘 작동한다고 말하고 싶습니다. 이와 같은 것과 결합하면 약간의 도움이 필요하지만 나중에 열을 분할하는 다중 열에 대한 단서가 없기 wrapfigure
때문에 이는 예상됩니다 .wrapfigure
업데이트
코드를 약간 개선하여 이제 열 유형의 변경 사항도 추적할 수 있게 되었습니다. 이로 인해 다른 LaTeX 실행이 필요하다고 감지되면 "레이블이 변경되었을 수 있습니다. 상호 참조를 올바르게 얻으려면 다시 실행하세요."라는 잘 알려진 경고가 생성됩니다.
따라서 다음과 같은 출력은 사용자가 해당 경고를 무시한 경우에만 발생해야 합니다.
업데이트 II
위 버전은 mccolaction
현재 CTAN에 없는 SVN 버전에 대해 작성되었습니다. 대답으로다중 열의 첫 번째 열 내에 있는 경우에만 열 나누기두 버전 모두에서 작동하는 업데이트된 패키지를 제공했습니다 multicol
.
업데이트 III
위에서 설명한 기능은 이제 multicol 버전 1.8 이상에서 사용할 수 있습니다. 비용이 많이 들기 때문에 자동으로 활성화되지 않습니다. --- 옵션을 사용하여 요청해야 합니다 colaction
. 이후에는 \docolaction
문서에서 사용할 수 있습니다.