1

Like many LaTeX users, I spend too much time tinkering around rather than writing the actual document. But I am wondering if anyone has attempted this or not.

I've been working on getting the first cell in a table to read as \section{"my section name"} that can be read by \tableofcontents. For reference, I am using Rstudio (v0.99.467) with Sweave,knitr,xelatex, etc. to write white papers with ggplots.

Currently, I am manually creating section headings (without \section; see below), but it would helpful to write each using \section as my documents are increasing in length. I've tried inserting \section in various locations in the tabularx block (see code below), but I am unable to get it to read. There doesn't seem to be much information on this. I'll try to explain this in a little more detail.

First, I've posted a few screenshots.

Example of Custom Format for Section Headings

Screenshot - Actual

Here's what the final output looks like.

enter image description here

Screenshot - Structure

To demonstrate the structure, here's is what section header looks like with all of of the borders turned on (recreated in pages). enter image description here

Current Code

\documentclass[a4paper]{article}

\usepackage{tabularx}

\begin{document}

\begin{tabularx}{\textwidth}{@{} l X @{} }
    \multirow{2}{*}{\fontsize{15}{10}\selectfont My First Section} & \\
    \cline{2-2}
    & \\
\end{tabularx}

\end{document}

Other tests:

Insert \section before name

\begin{tabularx}{\textwidth}{@{} l X @{} }
    \multirow{2}{*}{\fontsize{15}{10}\selectfont \section{My First Section}} & \\
    \cline{2-2}
    & \\
\end{tabularx}

Insert \section before \fontsize

\begin{tabularx}{\textwidth}{@{} l X @{} }
    \multirow{2}{*}{\section{{\fontsize{15}{10}\selectfont My First Section}}} & \\
    \cline{2-2}
    & \\
\end{tabularx}

I've tested the \sectionfont{} command, but could not get it to work. Would anyone have any suggestions? I'm wondering if this may be an issue with specifying too many things (tabularx, multirow, setting manual fontsize, borders, etc.).

Thanks for your help!

1

Not sure this is the good way.

\documentclass[a4paper]{article}

\usepackage{tabularx,multirow,sectsty}

\sectionfont{\fontsize{15}{10}\selectfont\sectabx}
\subsectionfont{\fontsize{15}{10}\selectfont\subsectabx}

\newcommand{\sectabx}[1]{%
\noindent\begin{tabularx}{\textwidth}{@{} l X @{} }
    \multirow{2}{*}{#1} & \\
    \cline{2-2}
    & \\
\end{tabularx}}

\newcommand{\subsectabx}[1]{%
\noindent\begin{tabularx}{\textwidth}{|@{} l| X @{}| }
    \hline
    \multirow{2}{*}{#1} & \\
    \cline{2-2}
    & \\
    \hline
\end{tabularx}}

\begin{document}

\section{My First Section}
bla bla
\subsection{My First subSection}
bla bla

\section*{My First Section}
bla bla
\subsection*{My First subSection}
bla bla

\end{document}

enter image description here

| improve this answer | |
  • Wow, this is absolutely perfect! Thanks for your help. – dcruvolo Oct 28 '15 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.