我使用罗马数字表示章节,使用拉丁字母表示子章节(没有拉丁字母表示章节)。当然,子章节 A 现在出现了多次。我引用了那些\ref{sec:title}
。输出始终是 A,无论我引用哪个子章节。我希望引用字母前面带有罗马数字的特定子章节。附件中,您可以找到一个最小的工作示例。我已经尝试通过添加来调整它\def\p@subsection{}
。
任何帮助,将不胜感激!
最好的
丹尼尔
\documentclass[12pt]{article}
\usepackage{alphalph}
\usepackage[toc,page]{appendix}
\usepackage{array}
\usepackage{amsmath,amsthm,verbatim,amssymb,amsfonts,amscd, graphicx}
\usepackage[toc,page]{appendix}
\usepackage{booktabs}
\usepackage{cite}
\usepackage{graphics}
\usepackage{etoolbox}
\usepackage{lscape}
\usepackage{multirow}
\usepackage[authoryear,round,url=false]{natbib}
%\usepackage[authordate]{biblatex-chicago}
\usepackage{rotating}
\usepackage[doublespacing]{setspace}
\usepackage[colorlinks,citecolor=blue, linkcolor=blue]{hyperref}
\usepackage{subcaption}
%\usepackage{subfig}
\usepackage{threeparttable}
\usepackage[tableposition=top]{caption}
\usepackage[section]{placeins}
\usepackage[multiple]{footmisc}
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{5ex}
% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
\newcommand{\figtext}[1]{
\vspace{0.5ex}
\captionsetup{textfont={small,singlespacing}}
\caption*{\hspace{0.5ex}\hangindent=1.5em #1}
}
\newcommand{\fignote}[1]{\figtext{\emph{Note:~}~#1}}
\newcommand{\figsource}[1]{\figtext{\emph{Source:~}~#1}}
% Add significance note with \starnote
\newcommand{\starnote}{\figtext{* p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01. Standard errors in parentheses.}}
%\renewcommand{\footnotesize}{\fontsize{12pt}{24}\selectfont}
%\renewcommand*{\footnotelayout}{\normalsize\doublespacing}
% *****************************************************************
% Cnew column types
% *****************************************************************
\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}}
\renewcommand*{\thesubfigure}{%
\alphalph{\value{subfigure}}%
}%
\makeatletter
% Patch case where name and year are separated by aysep
\patchcmd{\NAT@citex}
{\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb}%
\NAT@date}}
{\@citea\NAT@nmfmt{\NAT@nm}%
\NAT@aysep\NAT@spacechar\NAT@hyper@{\NAT@date}}{}{}
% Patch case where name and year are separated by opening bracket
\patchcmd{\NAT@citex}
{\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}%
{\@citeb\@extra@b@citeb}%
\NAT@date}}
{\@citea\NAT@nmfmt{\NAT@nm}%
\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi\NAT@hyper@{\NAT@date}}
{}{}
\renewcommand\thesection{\Roman{section}}
\renewcommand\thesubsection{\Alph{subsection}}
\renewcommand\@seccntformat[1]{\csname the#1\endcsname. }
\def\p@subsection{}
\makeatother
\begin{document}
\section{Hello}\label{sec:hello}
\subsection{World}\label{sec:world}
I test the reference to subsection \ref{sec:areyou}
\section{How}\label{sec:how}
\subsection{are you?}\label{sec:areyou}
\end{document}
答案1
因为\subsection
只是\@startsection
使用传递的参数进行调用,所以 etoolbox 在这里没有太大帮助。
\documentclass[12pt]{article}
\usepackage{alphalph}
\usepackage[toc,page]{appendix}
\usepackage{array}
\usepackage{amsmath,amsthm,verbatim,amssymb,amsfonts,amscd, graphicx}
\usepackage[toc,page]{appendix}
\usepackage{booktabs}
\usepackage{cite}
\usepackage{graphics}
\usepackage{etoolbox}
\usepackage{lscape}
\usepackage{multirow}
\usepackage[authoryear,round]{natbib}% error with url=false
%\usepackage[authordate]{biblatex-chicago}
\usepackage{rotating}
\usepackage[doublespacing]{setspace}
\usepackage[colorlinks,citecolor=blue, linkcolor=blue]{hyperref}
\usepackage{subcaption}
%\usepackage{subfig}
\usepackage{threeparttable}
\usepackage[tableposition=top]{caption}
\usepackage[section]{placeins}
\usepackage[multiple]{footmisc}
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{5ex}
% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
\newcommand{\figtext}[1]{
\vspace{0.5ex}
\captionsetup{textfont={small,singlespacing}}
\caption*{\hspace{0.5ex}\hangindent=1.5em #1}
}
\newcommand{\fignote}[1]{\figtext{\emph{Note:~}~#1}}
\newcommand{\figsource}[1]{\figtext{\emph{Source:~}~#1}}
% Add significance note with \starnote
\newcommand{\starnote}{\figtext{* p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01. Standard errors in parentheses.}}
%\renewcommand{\footnotesize}{\fontsize{12pt}{24}\selectfont}
%\renewcommand*{\footnotelayout}{\normalsize\doublespacing}
% *****************************************************************
% Cnew column types
% *****************************************************************
\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}}
\renewcommand*{\thesubfigure}{%
\alphalph{\value{subfigure}}%
}%
\makeatletter
% Patch case where name and year are separated by aysep
\patchcmd{\NAT@citex}
{\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb}%
\NAT@date}}
{\@citea\NAT@nmfmt{\NAT@nm}%
\NAT@aysep\NAT@spacechar\NAT@hyper@{\NAT@date}}{}{}
% Patch case where name and year are separated by opening bracket
\patchcmd{\NAT@citex}
{\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}%
{\@citeb\@extra@b@citeb}%
\NAT@date}}
{\@citea\NAT@nmfmt{\NAT@nm}%
\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi\NAT@hyper@{\NAT@date}}
{}{}
\renewcommand\thesection{\Roman{section}}
\renewcommand\thesubsection{\Alph{subsection}}
\renewcommand\@seccntformat[1]{\csname the#1\endcsname. }
\def\p@subsection{}
\let\oldsubsection=\subsection
\renewcommand{\subsection}[2][\empty]{%
\ifx\empty#1\relax
\oldsubsection[#2]{#2}%
\else
\oldsubsection[#1]{#2}%
\fi
\edef\@currentlabel{\thesection\thesubsection}}
\makeatother
\begin{document}
\section{Hello}\label{sec:hello}
\subsection{World}\label{sec:world}
I test the reference to subsection \ref{sec:areyou}
\section{How}\label{sec:how}
\subsection{are you?}\label{sec:areyou}
\end{document}