[Tex/LaTex] Numbering Theorems/Definitions in Lyx according to Subsection, Line Breaks after Text

amsthmlyxlyx-layoutstheorems

I am currently using Document > Settings > Modules > Theorems (Numbered by Type within Sections) in Lyx.

However, I need my theorems/definitions to be numbered according to subsection instead. i.e.

2 Introduction

2.1 Subsection …

Definition 2.1.1

Theorem 2.1.2

2.2 Subsection 2

Theorem 2.2.1

Additionally, I also want the text after the labels to be in a new line (instead of continuing after the bold text), i.e.

Definition 2.2.2

The definition of formula is…

I would also like to state that I am rather new to lyx so I am not familiar with editing TeX code (if required) in the editor so detailed steps would really be appreciated.

Thank you!

Edit 1: MWE (I removed mostly font related code)

% Preview source code

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\begin_modules
theorems-ams-bytype
theorems-sec-bytype
\end_modules
\maintain_unincluded_children false
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\noindent
\begin_inset CommandInset toc
LatexCommand tableofcontents

\end_inset


\end_layout

\begin_layout Standard
\paragraph_spacing onehalf
\noindent
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Section
\paragraph_spacing onehalf
\noindent
Title
\series bold
 1
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
numberwithin{equation}{section}
\end_layout

\end_inset


\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
setlength{
\backslash
parindent}{1.5pt}
\end_layout

\end_inset


\end_layout

\begin_layout Section
\paragraph_spacing onehalf
\noindent
Title 2
\end_layout

\begin_layout Subsection
\paragraph_spacing onehalf
\noindent
Sub 1
\end_layout

\begin_layout Subsection
\paragraph_spacing onehalf
\noindent
Sub 2
\end_layout

\begin_layout Definition
\noindent
My first definition
\end_layout

\end_body
\end_document

Best Answer

I do not know whether it's possible from within LyX, but here is what you have to add to you preamble to obtain it:

\newtheoremstyle{break}%
{5pt}{4pt}% spaces added before and after the environment
{\itshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{break}
\newtheorem{theorem}{Theorem}[subsection]

\newtheoremstyle{defbreak}%
{5pt}{4pt}% spaces added before and after the environment
{\upshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{defbreak}
\newtheorem{defn}{Definition}[subsection]

enter image description here

Here is the full code (slightly modified):

\documentclass{article}
\usepackage{amsthm}
\usepackage{lipsum}

\newtheoremstyle{break}%
{5pt}{4pt}% spaces added before and after the environment
{\itshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{break}
\newtheorem{thm}{Theorem}[subsection]

\newtheoremstyle{defbreak}%
{5pt}{4pt}% spaces added before and after the environment
{\upshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{defbreak}
\newtheorem{Def}{Definition}[subsection]

\begin{document}

\section{Introduction}
\subsection{A first subsection}
\lipsum[3]

\begin{thm}
  A silly test theorem. A silly test theorem. A silly test theorem. A silly test theorem. A silly test theorem.
\end{thm}

\lipsum[4]
\begin{Def}
 This is a \texttt{defbreak} style example. Some text. Some more text. Some more text. Some more text.
\end{Def}
\lipsum[5]

\end{document}