나는 TikZ 솔루션의 수정된 버전을 사용합니다.다른 질문프로그램의 버튼으로 표시하기 위해 일부 텍스트 주위에 둥근 사각형을 그립니다. 단일 문자에는 문제가 없지만 더 긴 용어를 사용하면(내 프로그램에서 버튼 이름이 지정됨) Overfull \hboxes에 문제가 발생합니다.
MWE:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{tikz}
\newcommand*\rectangled[1]{\tikz[baseline=(char.base)]{
\node[shape=rectangle,draw,inner sep=2pt, rounded corners=4pt, thick] (char) {\sffamily{#1}};}}
\begin{document}
A rectangled number \rectangled{1}: No problem normally as it is used as normal charakter and TeX can set it in the right position.
A button with a longer name is marked using the same command and \rectangled{creates an Overfull \textbackslash hbox} if it is set to the end of a line.
\end{document}
생성된 출력은 다음과 같습니다.
더 이상 문제가 발생하지 않을 때까지 문장을 재배열하는 것보다 이러한 Overfull \hbox를 방지하는 더 나은 솔루션이 있습니까?
답변1
A는 sloppypar
일시적으로 문제를 극복할 수 있도록 해줄 것입니다. 이 문제는 줄 끝에 조판하려는 대형 상자에서 발생합니다.
이 sloppypar
기능(또는 \sloppy
전체 문서에 대해)은 TeX의 페널티를 변경하여 단어 사이의 공백을 크게 늘리는 대신 여백 초과를 방지하는 데 더 중점을 둡니다. "공짜 점심"은 없습니다.
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{tikz}
\newcommand*\rectangled[1]{\tikz[baseline=(char.base)]{
\node[shape=rectangle,draw,inner sep=2pt, rounded corners=4pt, thick] (char) {\sffamily#1};}}
\begin{document}
A rectangled number \rectangled{1}: No problem normally as it is used as normal charakter and TeX can set it in the right position.
\begin{sloppypar}
A button with a longer name is marked using the same command and \rectangled{creates an Overfull \textbackslash hbox} if it is set to the end of a line.
\end{sloppypar}
\end{document}
답변2
다음은 줄 바꿈을 허용하고 두 부분 모두에 열린 직사각형을 사용하는 버전입니다. \tikzmark
텍스트의 시작과 끝을 표시하는 데 사용되며 텍스트가 조판된 후에 타원이 그려집니다.
노트:
이를 위해서는 두 번의 실행이 필요합니다. 첫 번째는 위치를 결정하고 두 번째는 도면을 작성합니다.
텍스트가 페이지 경계를 넘으면 작동하지 않습니다.
의 값은
\RoundedCorner
의 현재 값보다 클 수 없습니다2.0pt
. 그렇지 않으면 둥근 모서리에 아티팩트가 생깁니다.arc
더 큰 반경이 필요한 경우 수동으로 그린 그림을 대신 사용할 수도 있습니다.\InnerSep
추가되는 추가 수평 간격을 조정하기 위해 값을 조정할 수 있습니다.~ 전에그리고~ 후에텍스트.출처
\tikzmark
는텍스트 본문 옆에 큰 중괄호 추가.주석을 해제할 수 있습니다.패키지
showframe
페이지 여백을 보려면.
암호:
\documentclass{article}
%\usepackage{showframe}% to see page boundaries
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{decorations.pathreplacing}
\newcommand*{\InnerSep}{1pt}% Only applied to x directions
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[inner sep=0] (#1) {};}
%% https://tex.stackexchange.com/questions/33703/extract-x-y-coordinate-of-an-arbitrary-point-in-tikz
\newdimen\XCoordA
\newdimen\YCoordA
\newdimen\XCoordB
\newdimen\YCoordB
\newcommand*{\ExtractCoordinate}[3]{\path (#3); \pgfgetlastxy{#1}{#2};}%
\newcommand*{\RoundedCorner}{2.0pt}% <-- MUST NOT BE ANY LARGER
\tikzset{My Line Style/.style={rounded corners=\RoundedCorner, thick, blue}}
\newcommand*\rectangled[2][]{%
\tikzmark{Start Mark}#2\tikzmark{End Mark}%
\begin{tikzpicture}[overlay,remember picture]
\ExtractCoordinate{\XCoordA}{\YCoordA}{Start Mark}
\ExtractCoordinate{\XCoordB}{\YCoordB}{End Mark}
\ifdim\YCoordA=\YCoordB% Starts and ends on same line
\draw[My Line Style,#1]
([shift={(-\InnerSep,-0.3*\baselineskip)}]Start Mark.south east)
rectangle
([shift={(\InnerSep,0.7*\baselineskip)}]End Mark.north west)
;
\else% Starts on a different line
\coordinate (Right Hand Edge) at (Start Mark -| current page text area.east);
\coordinate (Left Hand Edge) at (End Mark -| current page text area.west);
\draw [My Line Style,#1]% Draw start of oval rectangle
([yshift=-0.3*\baselineskip]Right Hand Edge)
-| ([xshift=-\InnerSep]Start Mark.west)
|- ([yshift=0.7*\baselineskip]Right Hand Edge)
;
\draw [My Line Style,#1]% Draw end of oval rectangle
([yshift=-0.3*\baselineskip]Left Hand Edge)
-| ([xshift=\InnerSep]End Mark.east)
|- ([yshift=0.7*\baselineskip]Left Hand Edge)
;
\fi%
\end{tikzpicture}%
}
\begin{document}
A rectangled number \rectangled{1}, or \rectangled[magenta]{word}: No problem
normally as it is used as normal character and TeX can set it in the right position.
A button with a longer name marked using the same command \rectangled[red]{used to
create an Overfull \textbackslash hbox} if it was set to the end of a line.
A button with a even longer name \rectangled[brown]{no longer creates a Overfull
\textbackslash hbox when it crosses a line} boundary.
\end{document}