[Tex/LaTex] How to create a preface in LaTeX

structuretable of contents

I am wondering on how I could insert a preface before the table of contents.
The page would be roman enumerated but not put in the actual table of content. The initial part of my code is:

\documentclass[12pt, a4paper]{article}
\usepackage{a4wide}
\documentclass[12pt, openright ]{book}
\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{1.2}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{array}
\usepackage{float}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{graphicx}
\begin{document}
\

begin{titlepage}
    \pagenumbering{Roman} 

Title


    \end{titlepage}

    \shipout\null

\tableofcontents
\listoffigures
\listoftables

Best Answer

enter image description here

Use this code to define a preface environment

% ===== Define a preface environment =====
\newcommand{\prefacename}{Preface}
\newenvironment{preface}{
    \vspace*{\stretch{2}}
    {\noindent \bfseries \Huge \prefacename}
    \begin{center}
        % \phantomsection \addcontentsline{toc}{chapter}{\prefacename} % enable this if you want to put the preface in the table of contents
        \thispagestyle{plain}
    \end{center}%
}
{\vspace*{\stretch{5}}}

Full code

\documentclass[12pt, openright]{book}
\usepackage{a4wide}
\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{1.2}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{array}
\usepackage{float}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{blindtext}



\usepackage{tocloft}


    % ===== Define abstract environment =====
    \newcommand{\prefacename}{Preface}
    \newenvironment{preface}{
        \vspace*{\stretch{2}}
        {\noindent \bfseries \Huge \prefacename}
        \begin{center}
            % \phantomsection \addcontentsline{toc}{chapter}{\prefacename} % enable this if you want to put the preface in the table of contents
            \thispagestyle{plain}
        \end{center}%
    }
    {\vspace*{\stretch{5}}}

\begin{document}

\pagestyle{empty}

\begin{titlepage}

Title

\end{titlepage}

\shipout\null

\frontmatter
\pagenumbering{Roman} 

\begin{preface}
    \blindtext
\end{preface}

\clearpage

\tableofcontents

\clearpage
\listoffigures

\clearpage
\listoftables



\mainmatter

\Blinddocument

\end{document}
Related Question