如何制作一个两端对齐的彩色文本面板,并在其周围连续显示文本

如何制作一个两端对齐的彩色文本面板,并在其周围连续显示文本

我是 LaTeX 的新手,正在尝试制作一个右对齐或左对齐的彩色面板,其中有文本,而文本则围绕着它。我尝试使用迷你页面和使用 定义文本框tcolorbox,但我无法让正常的页面文本围绕着它。

代码示例:

% Placement
\usepackage[document]{ragged2e}

% Textboxes
\usepackage[margin=2cm]{geometry}
\usepackage[most]{tcolorbox}

\newtcolorbox{textbox}[1][]{%
  sharp corners,
  enhanced,
  colback=PaleGoldenrod,
  height=10cm,
  attach title to upper,
  #1
}
\begin{document}
...

Lorem ipsum doler et cetera..

\hfill\begin{minipage}{7cm}
\begin{flushright}
  \noindent\fcolorbox{black}{PaleGoldenrod}{
    \parbox[t][5cm][c]{5.3cm}{ \hspace*{0.25cm} I would like there to be text to the left

   }%
  }%
\end{flushright}
\end{minipage}


\begin{textbox}[width=7cm]
\begin{flushright}
I want there to be text to the right
\end{flushright}
\end{textbox}

Lorem ipsum doler et cetera..

我的问题

如果这是一个初学者的问题,我很抱歉 - 我觉得这是一个常见的要求,但我在网上找不到答案。

答案1

正如承诺的那样,通过另一种方式来实现您想要做的事情。

\documentclass[a4paper,11pt]{article}

\usepackage[top=2cm,left=2cm]{geometry}

\usepackage[x11names]{xcolor}

\usepackage[most]{tcolorbox}

\newtcolorbox{lefttextbox}[1][]{%
    sharp corners,
    enhanced,
    breakable,
    colback=LightGoldenrod1,    % PaleGoldenrod isn't defined in x11names
%   height=10cm,                % uncomment when needed
    width=7cm,
    attach title to upper,
    halign title=flush left,
    coltitle=DarkGoldenrod4,
    title=#1 --\space,
    halign=flush left,
    right=7.5mm                 % just to amplify the alignment
}

\newtcolorbox{righttextbox}[1][]{%
    sharp corners,
    enhanced,
    breakable,
    colback=LightGoldenrod1, %
    %   height=10cm,
    width=7cm,
    attach title to upper,
    halign title=flush right,
    coltitle=DarkGoldenrod4,
    title=#1 --\space,
    halign=flush right,
    left=7.5mm
}

%===== Paracol settings ===== 
\usepackage{paracol}

\footnotelayout{m}
\globalcounter{table}
\globalcounter{figure}
\setlength{\columnsep}{10mm}

\usepackage{lipsum}

\begin{document}
    \lipsum[1]

\columnratio{0.50,0.50}
\begin{paracol}{2}
    \lipsum[2]
\switchcolumn[1]
    \begin{lefttextbox}[Left aligned]
        \lipsum[1][1-2]
    \end{lefttextbox}
\switchcolumn[0]*                   % ensures correct alignment of column entries
    \begin{righttextbox}[Right aligned - ]
        \lipsum[1][3-4]
    \end{righttextbox}
\switchcolumn[1]
    \lipsum[2]
\end{paracol}

    \lipsum[3]
    
\end{document}

您必须调整某些选项以满足您的需要。例如,框的高度和/或宽度、文本的颜色和/或背景等。

MWE 的结果是: 在此处输入图片描述

答案2

这是一个您可以尝试的快速方法

平均能量损失

\documentclass[12pt,letterpaper]{article}
\usepackage{fullpage}
%\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
\usepackage{amsmath,amsthm,amsfonts,amssymb,amscd}
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{tasks}
\usepackage{parskip}
\usepackage{multicol}
\usepackage[document]{ragged2e}
\usepackage[margin=2cm]{geometry}
\usepackage{wrapfig}
\usepackage[most]{tcolorbox}


\begin{document}
    ...
    
    \begin{wrapfigure}{r}{7cm}
        \begin{flushright}
            \noindent\fcolorbox{black}{gray}{
                \parbox[t][5cm][c]{5.3cm}{ \hspace*{0.25cm} I would like there to be text to the left
                }%
            }%
        \end{flushright}
    \end{wrapfigure}
    
    Lorem ipsum doler et cetera..
    
    \begin{wrapfigure}{l}{7cm}
        \begin{flushleft}
            \noindent\fcolorbox{black}{gray}{
            \parbox[t][5cm][c]{5.3cm}{ \hspace*{0.25cm} I would like there to be text to the right
            }%
        }%
        \end{flushleft}
    \end{wrapfigure}

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.

This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel. This is some normal text that will continue around the colored panel.
\end{document}

输出

在此处输入图片描述

相关内容