framed 環境を使うと hbox があふれる

framed 環境を使うと hbox があふれる

- Toshio Otaguro の投稿
返信数: 5
framed 環境を使って四角い枠で囲まれた文書がページをまたぐような文書を組み版しようとしています.環境のカスタマイズは
http://xyoshiki.web.fc2.com/tex/framed.html
の中の例をそのままコピーして使っています.すると,framewithtitle 環境ではエラーなし,titledframe 環境では環境に入るときと出るときに overfull hbox が出ます.私が求めている書式は titledframe なのですが,自力では直せなくて困っています.以下再現ソースです.
----------

\documentclass[uplatex,dvipdfmx,ja=standard,11pt,b5paper,openany]{bxjsbook}

\usepackage[T1]{fontenc}
\usepackage{lmodern} % Latin Modern Font for alphabets
\usepackage{textcomp}
\usepackage{ascmac}

\usepackage{framed} % multi-page frame environment
% ----- setup of framed environment -----
% http://xyoshiki.web.fc2.com/tex/framed.html
\makeatletter
\newcommand*{\frametitle}[1]{\strut#1}
\newif\ifcontframe

\newcommand*{\Fr@meSetup}[2]{%
\fboxrule=\FrameRule \fboxsep=\FrameSep
\global\contframefalse
\def\Fr@meFirst{\textbf{#2}}%
\def\Fr@meCont{\textbf{#1}}%
\def\FrameCommand##1{%
\Title@Fr@me{\Fr@meCurrent}{##1}%
\global\let\Fr@meCurrent\Fr@meNext
\ifcontframe
\global\let\Fr@meNext\Fr@meCont
\fi
\global\contframetrue}%
\global\let\Fr@meCurrent\Fr@meFirst
\global\let\Fr@meNext\Fr@meFirst}

\newcommand*{\FrameTitle}[1]{%
\nobreak \vskip -0.7\FrameSep
\rlap{\frametitle{#1}}\nobreak\nointerlineskip
\vskip 0.7\FrameSep}

\newenvironment{framewithtitle}[2][\Fr@meFirst\ (cont.)]{%
\def\Title@Fr@me##1##2{%
\fbox{\vbox{\FrameTitle{##1}%
\hbox{##2}}}}%
\Fr@meSetup{#1}{#2}
\MakeFramed{%
\advance\hsize-\width
\FrameRestore}}%
{\global\contframefalse
\endMakeFramed}

\newenvironment{titledframe}[2][\Fr@meFirst\ (cont.)]{%
\def\Title@Fr@me##1##2{%
\vbox{\FrameTitle{##1}%
\noindent\fbox{##2}}}
\Fr@meSetup{#1}{#2}%
\MakeFramed{%
\advance\hsize-\width
\advance\hsize -2\FrameRule
\advance\hsize -2\FrameSep
\FrameRestore}}%
{\global\contframefalse
\endMakeFramed}
\makeatother
% -----

\begin{document}

\begin{framewithtitle}{Box~1.1 数学的慣習}
この本では変数名は通常の物理学の慣習に従う.つまり変数名は一文字で書く.
\end{framewithtitle}

\begin{titledframe}{Box~1.1 数学的慣習}
%=> Overfull \hbox (10.26472pt too wide) in paragraph at lines 67--67
この本では変数名は通常の物理学の慣習に従う.つまり変数名は一文字で書く.
\end{titledframe}
%=>Overfull \hbox (10.26472pt too wide) in paragraph at lines 70--70

\end{document}
----------

titledframe 環境の定義をどこかちょっと修正すれば直ると思うのですが,自力ではうまくいきません.また枠の幅自体を少し小さくするにはどうすればよいかも知りたいです.どなたかのお知恵を拝借したく,お願いする次第です.
Toshio Otaguro への返信

Re: framed 環境を使うと hbox があふれる

- 髙橋 政晴 の投稿

framedを普段使わないので、質問者様の意向には添えていませんが、参考程度にtcolorboxでの解決策を示します。

出力だけ寄せたいというのであればtcolorboxの使用も使えると思います。以下に例を示します。

※見た感じで作ったものなので寸法などは正確ではありません。また、3つ目のものは「枠の幅自体を少し小さく」したものです。


\documentclass[uplatex,dvipdfmx,ja=standard,11pt,b5paper,openany]{bxjsbook} \usepackage{tikz,tcolorbox} \tcbuselibrary{skins,breakable} \DeclareTColorBox{framewithtitle}{ o }{enhanced,colback=white,colframe=black,boxrule=0.2mm,sharp corners,breakable,top=7mm, underlay={ \path[draw]([xshift=2mm,yshift=-4mm]frame.north west)node[right]{\bfseries #1}; }} \DeclareTColorBox{titledframe}{ o }{enhanced,colback=white,colframe=black,boxrule=0.2mm,sharp corners,breakable,enlarge top by=8mm, underlay={ \path[draw]([xshift=2mm,yshift=4mm]frame.north west)node[right]{\bfseries #1}; }} \DeclareTColorBox{smalltitledframe}{ o }{enhanced,colback=white,colframe=white,boxrule=0.2mm,sharp corners,breakable,enlarge top by=8mm,right=5mm,left=5mm, underlay={ \path[draw,semithick]([xshift=3mm]frame.north west)--([xshift=-3mm]frame.north east)--([xshift=-3mm]frame.south east)--([xshift=3mm]frame.south west)--cycle; \path[draw]([xshift=2mm,yshift=4mm]frame.north west)node[right]{\bfseries #1}; }} \begin{document} \begin{framewithtitle}[Box~1.1 数学的慣習] この本では変数名は通常の物理学の慣習に従う.つまり変数名は一文字で書く. \end{framewithtitle} \begin{titledframe}[Box~1.1 数学的慣習] この本では変数名は通常の物理学の慣習に従う.つまり変数名は一文字で書く. \end{titledframe} \begin{smalltitledframe}[Box~1.1 数学的慣習] この本では変数名は通常の物理学の慣習に従う.つまり変数名は一文字で書く. \end{smalltitledframe} \end{document}
髙橋 政晴 への返信

Re: framed 環境を使うと hbox があふれる

- Toshio Otaguro の投稿
高橋様,
さっそくのご回答大変ありがとうございます.私は tcolorbox は使ったことがないので大変勉強になります.拝見したところ私が望むことはほとんど実現されているように思いますが,一点だけ,枠がページをまたいだ場合,次のページの枠のタイトルの末尾に (cont.) とか(続き)という文言が自動的に入るようにしたいのです.これは framed 環境では実現できているので,ぜひ取り込みたいと思います.可能であればご教示いただけると幸いです.
Toshio Otaguro への返信

Re: framed 環境を使うと hbox があふれる

- 髙橋 政晴 の投稿

妥協案ですが…

昨日示したもののの定義を次のように変更すると良いかもしれません


\DeclareTColorBox{titledframe}{ o }{enhanced,colback=white,colframe=black,boxrule=0.2mm,sharp corners,breakable,enlarge top by=8mm, underlay={ \path[draw]([xshift=2mm,yshift=4mm]frame.north west)node[right]{\bfseries #1}; }, overlay first={ \draw[line width=.5pt] (frame.south west)--(frame.south east); \node[anchor=north east] at (frame.south east) {Continue\dots};}, overlay middle={ \draw[line width=.5pt] (frame.south west)--(frame.south east); \draw[line width=.5pt] (frame.north west)--(frame.north east); \node[anchor=south east] at (frame.north east) {\dots Continue}; \node[anchor=north east] at (frame.south east) {Continue\dots};}, overlay last={ \draw[line width=.5pt] (frame.north west)--(frame.north east); \node[anchor=south east] at (frame.north east) {\dots Continue}; }}

※変更するのはこの部分だけで良いはずです。あとは昨日のままで添付したような出力になるはずです

髙橋 政晴 への返信

Re: framed 環境を使うと hbox があふれる

- Toshio Otaguro の投稿
高橋様,
ご提示の方法で望みの結果が得られることを当方の環境でも確認しました.これを使ってみようと思います.
重ねて感謝いたします.