I believe you need to load the ACM-Reference-Format-Journals
style to get citations and references in the form described in the excerpts you've posted. I.e., issue the command
\bibliographystyle{ACM-Reference-Format-Journals}
instead of \bibliographystyle{acm}
. If you don't already have this style file, go to the ACM LaTeX Style Guide webpage and download and unpack any one of the three zip files for authors (v2-acmsmall.zip, v2-acmlarge.zip, v2-acmtog.zip), and then copy the .bst
file to the directory that contains your TeX file(s).
To get authoryear-style citations, you should also load the natbib
package.
Addendum Feb. 2017: The ACM LaTeX style guide webpage appear to have migrated to https://www.acm.org/publications/acm-latex-style-guide-3jan2017.
Addendum Apr. 2021: The ACM LaTeX style guide webpage has migrated yet again. It is currently available at ACM Primary Article Templates AND Publication Workflow. Note that there are separate templates, depending on whether your computer uses MacOS or Windows. (I have no idea what users of Linux, etc, might want to do.) The ACM's template files are now also available in an Overleaf depository.
You can move the \bibliographystyle
to the preamble or whatever, so it is easier to switch out.
That much is unobjectionable. However, everything suggested below this point is subject to a large caveat:
If you are submitting source - as opposed to PDF - you should
not do this as it will only annoy. In particular, it will piss off copy editors no end. They do not want a highly
customised preamble and a body which uses a bunch of user-defined
macros.
Caveat emptor
You could handle the tabular in this way by providing a command which will not overwrite an existing definition, but only supply a default if none is defined.
\documentclass{IEEEtran}
\providecommand\tbl[2]{%
\caption{#1}%
#2}
\bibliographystyle{IEEEtran}
\begin{document}
\begin{table}[htbp]
\centering
\tbl{My Table Title \label{tab:label1}}{
\begin{tabular}{|l|l|}\hline
Key & Value \cite{Lastname2010title} \\\hline
\end{tabular}
}
\end{table}
% Currently I have to use this
Lastname et al. \cite{Lastname2010title} present a technique.
\bibliography{\jobname}
\end{document}
produces
Switching classes means we need to alter the preamble to use the relevant bibliography style, but the \providecommand
can stay. We don't need it, but it does no harm. (It will result in an infinitesimal increase in compilation time as TeX will read the code, but it will not make any difference to the compiled result.)
We also still need to change \cite
to \citeN
etc. as applicable.
\documentclass{acmsmall}
\providecommand\tbl[2]{%
\caption{#1}%
#2}
\bibliographystyle{ACM-Reference-Format-Journals}
\begin{document}
\begin{table}[htbp]
\centering
\tbl{My Table Title \label{tab:label1}}{
\begin{tabular}{|l|l|}\hline
Key & Value \cite{Lastname2010title} \\\hline
\end{tabular}
}
\end{table}
\citeN{Lastname2010title} present a technique.
\bibliography{\jobname}
\end{document}
produces
Note that you could obviously \providecommand
for \citeN
, too. But you would still need to change the structure of the text in that case.
You could work around this by defining a custom citation command, \myciteN{}{}
which does something different, depending on which class is loaded. For example, using etoolbox
for testing whether \citeN
is defined,
\documentclass{acmsmall}
\usepackage{etoolbox}
\providecommand\tbl[2]{%
\caption{#1}%
#2}
\providecommand\myciteN[2]{%
\ifundef\citeN{%
#1 \cite{#2}%
}{%
\citeN{#2}%
}%
}
\bibliographystyle{ACM-Reference-Format-Journals}
\begin{document}
\begin{table}[htbp]
\centering
\tbl{My Table Title \label{tab:label1}}{
\begin{tabular}{|l|l|}\hline
Key & Value \cite{Lastname2010title} \\\hline
\end{tabular}
}
\end{table}
\myciteN{Lastname et al.}{Lastname2010title} present a technique.
\bibliography{\jobname}
\end{document}
produces
while merely changing the class and the bibliography style in the preamble as follows
\documentclass{IEEEtran}
\usepackage{etoolbox}
\providecommand\tbl[2]{%
\caption{#1}%
#2}
\providecommand\myciteN[2]{%
\ifundef\citeN{%
#1 \cite{#2}%
}{%
\citeN{#2}%
}%
}
\bibliographystyle{IEEEtran}
\begin{document}
\begin{table}[htbp]
\centering
\tbl{My Table Title \label{tab:label1}}{
\begin{tabular}{|l|l|}\hline
Key & Value \cite{Lastname2010title} \\\hline
\end{tabular}
}
\end{table}
\myciteN{Lastname et al.}{Lastname2010title} present a technique.
\bibliography{\jobname}
\end{document}
now produces
This means that you can write, for example,
\documentclass{IEEEtran}
% \documentclass{acmsmall}
\usepackage{etoolbox}
\providecommand\tbl[2]{%
\caption{#1}%
#2}
\providecommand\myciteN[2]{%
\ifundef\citeN{%
#1 \cite{#2}%
}{%
\citeN{#2}%
}%
}
\bibliographystyle{IEEEtran}
% \bibliographystyle{ACM-Reference-Format-Journals}
\begin{document}
\begin{table}[htbp]
\centering
\tbl{My Table Title \label{tab:label1}}{
\begin{tabular}{|l|l|}\hline
Key & Value \cite{Lastname2010title} \\\hline
\end{tabular}
}
\end{table}
\myciteN{Lastname et al.}{Lastname2010title} present a technique.
\bibliography{\jobname}
\end{document}
and merely comment/uncomment the class line and one preamble line to switch between formats.
Best Answer
With
ACM-Reference-Format.bst
you can add the date of access of an URL to thelastaccessed
field (only for@misc
entries, though).