1

I put the title of my examples in a single table cell to create a look of half a box around it with the following code

\newtheorem*{example}{\begin{tabular}{r|}example\\\hline\end{tabular}} 

How can I do something similar for section titles? I tried:

\makeatletter
\renewcommand\section{\begin{tabular}{r|}\\\hline\end{tabular}}
\makeatother

but this doesn't work.

A minimal working example:

\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}

user283579
  • 121
  • 6
  • 5
    Perhaps you should start by explaining what your overall end goal with this is. This seens rather strange to me. – daleif Jun 08 '23 at 12:23
  • Welcome to TeX.SE. – Mico Jun 08 '23 at 12:28
  • 1
    As already said in chat, please add a MWE (a short but compileable test document) to your question. How to customise the section layout heavily depends on your documentclass. – samcarter_is_at_topanswers.xyz Jun 08 '23 at 13:09
  • Have you tried the reverse approach, i.e., a single-cell tabular env. into the argument of \section? – Mico Jun 08 '23 at 13:25
  • @samcarter_is_at_topanswers.xyz I've added some part of my tex file. – user283579 Jun 08 '23 at 13:30
  • @user91500 - No \renewcommands. Just, say, \section{\begin{tabular}{|c|} aa \\ bb \end{tabular}}. I must confess that I, like the other commenters, am absolutely clueless as to what you're trying to achieve. Incidentally, the fact that you prefer to refuse to say what it is that you may be trying to achieve doesn't really help your cause. – Mico Jun 08 '23 at 13:43
  • 2
    How on earth can you have \section directives before \begin{document}?? This makes no sense at all. No wonder we're having major difficulties understanding what you're trying to do... – Mico Jun 08 '23 at 13:46
  • Following the comments I suggest to close this one, perhaps even delete it, to avoid using this approach. Doesn‘t sound useful to me. – MS-SPO Jun 08 '23 at 14:48
  • 1
    I'm voting to reopen this question. It seems clear that the OP tries to change the format of section titles. – samcarter_is_at_topanswers.xyz Jun 09 '23 at 09:40

1 Answers1

4

You could use the titlesec package to redefine the layout of the section heading:

\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}

enter image description here