%--------------------------------------------------------------------------------------------------------- %
\documentclass[english]{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb}
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage{newtxtext} %
\usepackage{setspace} %
\usepackage{xcolor} %
\usepackage{colortbl} %
\usepackage{stackengine} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry} %
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{layout} %
\usepackage{graphicx} %
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage[T1]{fontenc}
\setlength{\unitlength}{1mm} %
\begin{document}
\setstretch{1.10}
I wish to box the following phrases:
-------------------------------------------------------------------------------------------------------
\noindent \hspace{36pt} \hspace{1.2pt}\fbox{over the moon}\hspace{1.2pt}, \hspace{1.5pt}\fbox{a mop up} \hspace{1.2pt}and \hspace{1.2pt}\hspace{1.2pt}\fbox{just in time}
-------------------------------------------------------------------------------------------------------
\noindent \hspace{0.8pt}so that the tops and bottoms of the first two boxes are at the same horizontal level as those \\ of \hspace{1.2pt}\textquotedblleft\hspace{1.2pt}just in time\hspace{1.2pt}\textquotedblright.
\noindent [boundary and fill colours would be nice, too]
\end{document}
答案1
像这样 ?
我只是在这里用 tcolorbox 修改了我的答案:https://tex.stackexchange.com/a/458876/138900
\newtcbox{\entoure}[1][yellow]{on line,colback=#1,colframe=#1!50!black,sharp corners,right skip=1.2pt,left skip=1.2pt,
before upper={\rule[-3pt]{0pt}{10pt}},boxrule=1pt,
boxsep=0pt,left=2pt,right=2pt,top=2pt,bottom=.5pt}
%--------------------------------------------------------------------------------------------------------- %
\documentclass[english]{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb}
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage{newtxtext} %
\usepackage{setspace} %
\usepackage{xcolor} %
\usepackage{colortbl} %
\usepackage{stackengine} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry} %
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{layout} %
\usepackage{graphicx} %
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage[T1]{fontenc}
\setlength{\unitlength}{1mm} %
\usepackage{tcolorbox}
\newtcbox{\entoure}[1][yellow]{on line,colback=#1,colframe=#1!50!black,sharp corners,right skip=1.2pt,left skip=1.2pt,
before upper={\rule[-3pt]{0pt}{10pt}},boxrule=1pt,
boxsep=0pt,left=2pt,right=2pt,top=2pt,bottom=.5pt}
\begin{document}
\setstretch{1.10}
I wish to box the following phrases:
-------------------------------------------------------------------------------------------------------
\noindent \hspace{36pt} \hspace{1.2pt}\fbox{over the moon}\hspace{1.2pt}, \hspace{1.5pt}\fbox{a mop up} \hspace{1.2pt}and \hspace{1.2pt}\hspace{1.2pt}\fbox{just in time}
\medskip
\noindent \hspace{36pt} \entoure{over the moon}, \entoure{a mop up} and \entoure{just in time}
-------------------------------------------------------------------------------------------------------
\noindent \hspace{0.8pt}so that the tops and bottoms of the first two boxes are at the same horizontal level as those \\ of \hspace{1.2pt}\textquotedblleft\hspace{1.2pt}just in time\hspace{1.2pt}\textquotedblright.
\noindent [boundary and fill colours would be nice, too]
\end{document}
答案2
当然,您可以使用 来做到这一点tcolorbox
,但如果您只想进行视觉格式化,而不需要管理换行符和分页符,那么您tikz
也可以使用普通的格式(诀窍是使用baseline
和anchor=base
,例如您所见这里和这里):
\documentclass[]{book}
\usepackage{xcolor} %
\usepackage[T1]{fontenc}
\usepackage{tikz}
\tikzset{
text hl box/.style={
anchor=base,
},
yellow with red/.style={
text hl box, draw=red, text=cyan, fill=yellow,
},
only greeny/.style={
text hl box, draw=none, fill=green!10,
},
only outside/.style={
text hl box, draw=purple,
},
}
\newcommand{\Strut}{% a bigger \strut
\vrule width 0pt depth 4pt height 14pt\relax
}
% handy commands
\newcommand{\letboxit}[2]{%
\tikz[baseline] \node[#1]{#2};%
}
\newcommand{\letboxits}[2]{% add a \strut
\tikz[baseline] \node[#1]{\strut #2};%
}
\newcommand{\letboxitS}[2]{% add a \Strut
\tikz[baseline] \node[#1]{\Strut #2};%
}
\parindent=0pt\parskip=\baselineskip
\begin{document}
I wish to box the following phrases:
\noindent\hrulefill
\noindent \hspace{36pt} \letboxit{yellow with red}{over the moon}, \letboxit{only greeny}{a mop up} and \letboxit{only outside}{just in time}.
If you want a box with the standard font height, use a \verb|\strut| and remove the \texttt{inner sep}:
% the inner xsep is needed for things like the "j"
\tikzset{text hl box/.style={anchor=base, inner sep=0pt, inner xsep=1pt}}
\noindent \hspace{36pt} \letboxits{yellow with red}{over the moon}, \letboxits{only greeny}{a mop up} and \letboxits{only outside}{just in time}.
\dots and you can play with a personal sized \verb|\Strut| also:
\noindent \hspace{36pt} \letboxitS{yellow with red}{over the moon}, \letboxitS{only greeny}{a mop up} and \letboxitS{only outside}{just in time}.
\noindent\hrulefill
\end{document}
如果你需要突出显示多行文本,那就不那么容易了。你可以研究答案这里和这里; 或者如果你可以/想要切换到 lualatex,还有更棒的lua-ul
包裹。