问题
构建一个环境,将一些文本放入一些框中,这些框应该可以在页面上拆分。和适应文本宽度。不幸的是,包mdframed
和tcolorboxes
有第一个选项,但没有第二个选项,因为这似乎varwidth
让它们不舒服。
建议的解决方案
搭建两个环境。
工作示例
\documentclass{article}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8x]{inputenc}
\usepackage{lmodern,textcomp}
\usepackage[italian]{babel}
% Related to math
\usepackage{amsmath,amssymb,amsfonts,amsthm}
% just for this example
\usepackage{blindtext}
% lists
\usepackage{enumerate}
\renewcommand{\labelitemii}{$\ast$}
\renewcommand{\labelitemiii}{--}
% colors
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,32,155}
\definecolor{myred}{RGB}{192,0,0}
\definecolor{mygray}{RGB}{68,84,106}
\definecolor{myred2}{RGB}{180,4,38}
\definecolor{myorange}{RGB}{238,132,104}
\definecolor{mygreen}{RGB}{26,152,80}
% url
\usepackage{hyperref}
% useful comments
\usepackage{varwidth}
\usepackage{mdframed}
\mdfdefinestyle{basemdstyle}{%
skipabove=1em,
skipbelow=1em,
innertopmargin=0.75em,
innerbottommargin=0.75em
}
\newmdenv[style=basemdstyle]{baseemph}
% breakable
\newcommand\lredemph[1]{%
\begin{baseemph}[fontcolor=myred]%
{#1}%
\end{baseemph}}
% width-adaptive
\newcommand\redemph[1]{\fbox{%
\begin{varwidth}{\textwidth}%
{\textcolor{myred}{#1}}%
\end{varwidth}%
}\par}
\begin{document}
\Blindtext
\lredemph{\textbf{this will go across pages.} \Blindtext}
\redemph{this will be just as large as the text}
\end{document}
答案1
内联添加的评论
\documentclass{article}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
% avoid utf8x use utf8 on old latex releases, use nothing on current releases \usepackage[utf8x]{inputenc}
\usepackage{lmodern}
% not needed in current releases textcomp
\usepackage[italian]{babel}
% Related to math
\usepackage{amsmath,amssymb,amsfonts,amsthm}
% just for this example (not very Italian:-)
\usepackage{blindtext}
% lists
\usepackage{enumerate} % I wrote this, but enumitem is better
\renewcommand{\labelitemii}{$\ast$}
\renewcommand{\labelitemiii}{--}
% colors
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,32,155}
\definecolor{myred}{RGB}{192,0,0}
\definecolor{mygray}{RGB}{68,84,106}
\definecolor{myred2}{RGB}{180,4,38}
\definecolor{myorange}{RGB}{238,132,104}
\definecolor{mygreen}{RGB}{26,152,80}
% url
\usepackage{hyperref}
% useful comments
\usepackage{mdframed}
\mdfdefinestyle{basemdstyle}{%
skipabove=1em,
skipbelow=1em,
innertopmargin=0.75em,
innerbottommargin=0.75em
}
\newmdenv[style=basemdstyle]{baseemph}
% breakable
%if the text takes multiple lines use mdframed otherwise fbox
\newcommand\lredemph[1]{%
\setbox0\vbox{{#1\par}}%
\ifdim\ht0>\baselineskip
\begin{baseemph}[fontcolor=myred]%
#1%
\end{baseemph}%
\else
\fbox{\textcolor{myred}{#1}}%
\fi}
\begin{document}
\Blindtext
\lredemph{\textbf{this will go across pages.} \Blindtext}
\lredemph{this will be just as large as the text}
\end{document}