我将示例的标题放在单个表格单元格中,以使用以下代码在其周围创建半个框的外观
\newtheorem*{example}{\begin{tabular}{r|}example\\\hline\end{tabular}}
我怎样才能对章节标题做类似的事情?我试过:
\makeatletter
\renewcommand\section{\begin{tabular}{r|}\\\hline\end{tabular}}
\makeatother
但这不起作用。
一个最小的工作示例:
\documentclass[a4paper,11pt]{book}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{array}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{0.5\linewidth}}
\renewcommand{\arraystretch}{1.5}
\renewcommand{\headrulewidth}{0pt}
\setlength\arrayrulewidth{1pt}
\theoremstyle{definition}
\newtheorem*{example}{\begin{tabular}{r|}example\\\hline\end{tabular}}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother
\begin{document}
\section*{first}
\begin{example}
content
\end{example}
\end{document}
答案1
您可以使用该titlesec
包来重新定义部分标题的布局:
\documentclass[a4paper,11pt]{book}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{array}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{0.5\linewidth}}
\renewcommand{\arraystretch}{1.5}
%\renewcommand{\headrulewidth}{0pt}
\setlength\arrayrulewidth{1pt}
\theoremstyle{definition}
\newtheorem*{example}{\begin{tabular}{r|}example\\\hline\end{tabular}}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother
\usepackage[explicit]{titlesec}
\titleformat{\section}{\bfseries}{\thesection}{.5em}{\begin{tabular}{r|}#1\\\hline\end{tabular}}
\begin{document}
\section*{first}
\begin{example}
content
\end{example}
\end{document}