다중 열: 왼쪽을 정렬하고 왼쪽에서 사용되지 않는 공간을 채웁니다. (이상한 페이지.)

다중 열: 왼쪽을 정렬하고 왼쪽에서 사용되지 않는 공간을 채웁니다. (이상한 페이지.)

존경하는 커뮤니티 여러분, 저는 두 개의 열로 구성된 문서 레이아웃을 가지고 있으며 일반적으로 다음 중 하나를 선택할 수 있다는 것을 알고 있습니다.

  1. 텍스트를 왼쪽으로 정렬하여 오른쪽에서 사용되지 않은 공간을 채우고
  2. 텍스트를 오른쪽으로 정렬하여 오른쪽에서 사용되지 않은 공간을 채웁니다.

텍스트를 왼쪽으로 정렬하면서 가장 긴 줄에 따라 전체 텍스트 상자를 열의 가능한 한 오른쪽에 배치하여 왼쪽에서 사용되지 않는 공간을 채우는 정렬을 어떻게 얻을 수 있습니까?

솔루션은 홀수 페이지의 전체 열에 영향을 주어야 하며(중앙에서 정의할 수 있어야 함), 텍스트의 너비를 미리 알 수 없습니다. 이는 모든 열마다 다를 수 있습니다.

귀하의 의견에 감사드립니다.

홀수 페이지에서 필요한 동작

답변1

이미지를 클릭하시면 더 나은 해상도로 보실 수 있습니다

편집 1: 홀수/짝수 페이지 확인 추가

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{lipsum}
\usepackage{array}
\usepackage{varwidth}
\usepackage{changepage}
\strictpagecheck
\def\maxwidth{13cm}
\newcolumntype{M}{>{\begin{varwidth}{\maxwidth}}l<{\end{varwidth}}}
\newenvironment{myenvi}
    {%
        \checkoddpage
        \ifoddpage
            \hfill\begin{tabular}{@{}M@{}}
        \fi
    }
    {%
        \checkoddpage
        \ifoddpage
            \end{tabular}\hspace{-3.5pt}
        \fi
    }

\setlength{\parskip}{1ex}
\begin{document}
\lipsum[1]

\begin{myenvi}
Oh, this is what I want!

I really want some lines like this

And this line is a bit too long, so it will be broken to some lines blah blah. And this line is a bit too long, so it will be broken to some lines. And this line is a bit too long, so it will be broken to some lines. And this line is a bit too long, so it will be broken to some lines.
\end{myenvi}

And some more normal lines

\begin{myenvi}
This is a short text for testing whose total width is clearly less than 10cm.

And this is an even shorter text.
\end{myenvi}

\lipsum[2-6]

\begin{myenvi}
This is the environment for check in an even page. It should be like normal text.

Yes, this is normal text!
\end{myenvi}

\lipsum[7]
\end{document}

1페이지(홀수):

여기에 이미지 설명을 입력하세요

2페이지(짝수):

여기에 이미지 설명을 입력하세요

원래 답변

tabular열 유형을 정의하고 사용\hfill

\documentclass{article}
\usepackage{lipsum}
\usepackage{array}
\usepackage{varwidth}
\newcolumntype{M}{>{\begin{varwidth}{10cm}}l<{\end{varwidth}}}

\setlength{\parskip}{1ex}
\begin{document}
\lipsum[1]

\hfill\begin{tabular}{@{}M@{}}
Oh, this is what I want!

I really want some lines like this

And this line is a bit too long, so it will be broken to some lines blah blah. And this line is a bit too long, so it will be broken to some lines. And this line is a bit too long, so it will be broken to some lines. And this line is a bit too long, so it will be broken to some lines.
\end{tabular}

\lipsum[2]
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보