我有一些代码当前创建这样的部分标题:
代码中执行此操作的相关行是:
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}l}#1\end{tabular}}
我想将其右对齐,以便它看起来像这样:
我该如何实现这一点?我尝试使用上面代码,但无济于事。
梅威瑟:
% these define the type of document and the look of the page
\documentclass[]{article}
\usepackage{lmodern}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage[margin=0.8in, top = 1.3in, headheight = 0.6in]{geometry}
%\usepackage[bottom, flushmargin]{footmisc}
\setlength{\footnotesep}{\baselineskip} % space between footnotes
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}
% colors
\usepackage{tcolorbox}
\usepackage{color} % colors
\usepackage{xcolor, colortbl} % more control over colors
\definecolor{c1}{HTML}{122084}
% heading formats
\usepackage[explicit]{titlesec}
\newcommand{\hsp}{\hspace{20pt}}
\titlespacing\section{0cm}{0in}{0in}
\titlespacing\subsection{0pt}{0.21in}{0.01in}
\titlespacing\subsubsection{0pt}{0.21in}{0in}
% table-related
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\usepackage{siunitx}
\newcommand\bstrut{\rule{0pt}{2.5ex}} % space before row
\newcommand\astrut{\rule[-1.25ex]{0pt}{0pt}} % space after row
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\thispagestyle{plain}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}l}#1\end{tabular}}
\section*{An Internationally \\ Renowned Title}
\end{document}
答案1
\documentclass[]{article}
\usepackage{lmodern}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage[margin=0.8in, top = 1.3in, headheight = 0.6in]{geometry}
%\usepackage[bottom, flushmargin]{footmisc}
\setlength{\footnotesep}{\baselineskip} % space between footnotes
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}
% colors
\usepackage{tcolorbox}
\usepackage{color} % colors
\usepackage{xcolor, colortbl} % more control over colors
\definecolor{c1}{HTML}{122084}
% heading formats
\usepackage[explicit]{titlesec}
\newcommand{\hsp}{\hspace{-10cm}}
\titlespacing\section{18cm}{0in}{0in}
\titlespacing\subsection{0pt}{0.21in}{0.01in}
\titlespacing\subsubsection{0pt}{0.21in}{0in}
% table-related
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol, makecell}
\usepackage{multirow, hhline}
\usepackage{siunitx}
\newcommand\bstrut{\rule{0pt}{2.5ex}} % space before row
\newcommand\astrut{\rule[-1.25ex]{0pt}{0pt}} % space after row
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\thispagestyle{plain}
\titleformat{\section}[hang]{\fontsize{30}{38}\selectfont\bfseries}{\color{c1}}{20pt}{\begin{tabular}[t]{@{\color{c1}\vrule width 3pt}>{\hsp}r}#1\end{tabular}}
\section*{An Internationally \\ Renowned Title}
\end{document}