How to make code block get a new line in Overleaf? - latex

I connot make my code block get a new line, as image
after compiled
It's my code
\makeatletter
\newif\if#restonecol
\makeatother
\let\algorithm\relax
\let\endalgorithm\relax
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}%[ruled,vlined]{
\usepackage{algpseudocode}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{document}
\begin{algorithm}
\caption{trace column}
\LinesNumbered
\KwIn{
$v$:当前访问的节点\newline
$c$:当前访问节点所要溯源的列
}
\KwOut{
$S$ :遍历所找到的根节点的集合
}
\textbf{Initialize} $S=\emptyset$ \;
\If{$v$ instanceof DataSourceNode}{
$n$.used=false\;
$n$.id=$v$.id\;
$n$.column=position of $c$ in $v$\;
$S=S\cup \{n\}$\;
}
\ElseIf{node instanceof JoinTreeNode}{
prenode[0]=node.input1\;
prenode[1]=node.input2\;
\For{i=0;i<2;i++}{
\If{$c$ is from prenode[i]}{
$S=S\cup trace$(prenode[i],position of $c$ in prenode[i])\;
\If{position of $c$ in prenode[i]=position of key in prenode[i]}{
$S=S\cup trace$(prenode[1-i],position of $c$ in prenode[1-i])\;
break\;
}
break\;
}
}
}
return $S$\newline
\end{algorithm}
\begin{algorithm}
\caption{trace column22}
....as the same code block....
\end{algorithm}
\end{document}
I tried to insert\newline and \par and it's useless.
Or could I create a new file and number the algorithm block from 2?
By the way, how to format code in Overleaf?

By using \hfil, you will add new line immediate after the end of algorithm .
if you want to add text in the new page immediate after the end of the algorithm. then you will use the \break.

Related

Adding a new line before lstnewenvironment

I'm using lstnewenvironment from the listings package to create new code blocks.
Using an example from its manual:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{\hfill pascal \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}
This generates a pascal code block like:
enter image description here
Now I want to add some text as 'tag' above the code line (at the end of that line) like:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{\hfill{\tiny pascal} \lstset{language=pascal}}
{}
This generates:
enter image description here
The tag text is at the same line with previous text, so I add \\ before the tag:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \\ \hfill{\tiny pascal} \lstset{language=pascal}}
{}
And tried
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \\ \hspace{\textwidth}{\tiny pascal} \lstset{language=pascal}}
{}
But both of the hfill and \hspace{\textwidth} don't work, the tag appears at the beginning of the line above:
enter image description here
The only way I can do is manually adding a blank line between the code block and previous text:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \hfill{\tiny pascal} \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}
Output:
enter image description here
My question is how to modify the \lstnewenvironment settings so that it can automatically add a new line between the code block and the previous text, with a tag at the end of that new line?
see https://tex.stackexchange.com/a/625934/36296
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{
\endgraf {\hfill \tiny pascal} \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}

How to add corresponding author in acmart class

I want "Corresponding author" to appear only where Authors’ address are mentioned [bottom of page]. It should not appear at the start [as shown in highlighted image].
I dont want to use \thanks or footnotes. I try authornote at differnt places but it appears separately.
The MWE is as follows:
\documentclass[acmlarge, authorversion]{acmart}
\AtBeginDocument{%
\providecommand\BibTeX{{%
\normalfont B\kern-0.5em{\scshape i\kern-0.25em b}\kern-0.8em\TeX}}}
\acmJournal{CSUR}
\acmVolume{}
\acmNumber{}
\acmArticle{}
\acmMonth{3}
\begin{document}
\title{Title is ACM}
\author{First}
\affiliation{%
\institution{University}
\city{city}
\country{country}}
\email{author#author.com}
\author{A}
\affiliation{%
\institution{University}
\city{city}
\country{country}}
\email{author#author.com}
\author{B}
\affiliation{%
\institution{University}
\city{city}
\country{country}}
\email{author#author.com}
\author{C}
\affiliation{%
\institution{(corresponding author), University}
\city{city}
\country{country}
}
\email{author#author.com}
% \thanks{(corresponding author)}
% \authornote{(corresponding author)}
\renewcommand{\shortauthors}{author et al.}
\begin{abstract}
abstract here...
\end{abstract}
\begin{CCSXML}
<ccs2012>
<concept>
<concept_id>10002944.10011122.10002945</concept_id>
<concept_desc>General and reference~Surveys and overviews</concept_desc>
<concept_significance>500</concept_significance>
</concept>
<concept>
<concept_id>10002978.10003006.10003013</concept_id>
<concept_desc>Security and privacy~Distributed systems security</concept_desc>
<concept_significance>300</concept_significance>
</concept>
</ccs2012>
\end{CCSXML}
\ccsdesc[500]{General and reference~Surveys and overviews}
\ccsdesc[300]{Security and privacy~Distributed systems security}
\keywords{ABC, XYZ}
\maketitle
\end{document}
\endinput

Including code using minted package inside an /ifthenelse block doesn't work in LATEX

I'm trying to generate a general document and (using\ifthenelse) having different pdf versions. When I try to include a block of code using the minted package, the pdf is generated without the code.
The code is included if I try it outside the \ifthenelse block. Inside the block is the only place when is not working. Same happens with \lstset.
\documentclass{article}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{ifthen}
\begin{document}
...
\newboolean{xcpp}
\setboolean{xcpp}{true}
\ifthenelse{xcpp}{
Test
\begin{listing}[ht]
\begin{minted}{cpp}
int main() {
int i=0;
for (i=1; i<10; i++){
int j=10;
std::cout<<i<<" j: "<<j<<std::endl;
}
std::cout<<"\ni al salir del ciclo: "<<i;
return 0;
}
\end{minted}
\caption{Minimal working example}
\label{listing:1}
\end{listing}
}{}
\end{document}
Fragile content such as code is always tricky inside the argument of another macro - but instead of trying to solve this problem, there is an easy workaround:
\documentclass{article}
\usepackage{minted}
\usepackage{xcolor}
\begin{document}
\newif\ifxcpp
\xcpptrue % <- comment this line to switch between the two versions
\ifxcpp
\begin{listing}[ht]
\begin{minted}{cpp}
int main() {
int i=0;
for (i=1; i<10; i++){
int j=10;
std::cout<<i<<" j: "<<j<<std::endl;
}
std::cout<<"\ni al salir del ciclo: "<<i;
return 0;
}
\end{minted}
\caption{Minimal working example}
\label{listing:1}
\end{listing}
\else
something else
\fi
\end{document}

convert bib file to \bibitem[\protect\citeauthoryear

I have a reference file (bib file) I want to convert it as
\bibitem[\protect\citeauthoryear{Allen C.W.}{1973}] {b1} Allen C.W., 1973,
Astrophysical quantities, ${3^{rd}}$ ed. (Athlone Press, London)
when I use
\nocite{*}
\bibliographystyle{apalike}
\bibliography{bibfile}
Output ppl file as
\bibitem[Allen, 1973]{allen1973astrophysical}
Allen, C.~W. (1973).
Combining natbib with the newapa style gives something similar:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
#BOOK{1973asqu.book.....A,
author = {{Allen}, C.~W.},
title = "{Astrophysical quantities}",
keywords = {ASTROPHYSICS, ASTRONOMICAL CONSTANTS, TABLES, HANDBOOKS},
booktitle = {London: University of London, Athlone Press, |c1973, 3rd ed.},
year = 1973,
adsurl = {https://ui.adsabs.harvard.edu/abs/1973asqu.book.....A},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
\end{filecontents*}
\usepackage{natbib}
\begin{document}
\cite{1973asqu.book.....A}
\bibliographystyle{newapa}
\bibliography{\jobname}
\end{document}
Resulting .bbl file:
\begin{thebibliography}{}
\bibitem[\protect\citeauthoryear{{Allen}}{{Allen}}{1973}]{1973asqu.book.....A}
{Allen}, C.~W. (1973).
\newblock {\em {Astrophysical quantities}}.
\end{thebibliography}

Grayed listing environment with LaTeX

Form this LaTeX-workshop, I found I could make this listing style.
http://img441.imageshack.us/img441/2739/screenshot20100717at112.png
by defining a new environment.
\definecolor{mittelgrau}{gray}{0.85}%
\lstdefinestyle{StyleCommand}{%
style=StyleListingBasic, backgroundcolor=\color{mittelgrau}, prebreak=\mbox{\textbackslash{}}%
}
\lstnewenvironment{bevel}[1][1] {\lstset{style=StyleCommand,linewidth=#1\linewidth}} {}%
Running the code, I get this error message.
ERROR: Package Listings Error: Couldn't load requested style.
What might be wrong?
I missed the \lstdefinestyle, and after some modification, I could make it work.
\documentclass{article}
\usepackage{color} % Farben
\usepackage{listings} % für Listings
% Listingdefinitionen
\lstdefinestyle{StyleListingBasic}{%
basicstyle=\ttfamily, % Schriftstil
frame=single, % einfacher Rahmen
framesep=1pt, % Abstand des Rahmens
framerule=0.8pt, % Linienstaerke des Rahmens
rulecolor=\color{mittelgrau}, % Farbe der Rahmenlinie
breaklines=true, % automatischen Umbruch aktivieren
breakindent=0pt % Einrueckung nach Umbruch
}
\definecolor{mittelgrau}{gray}{0.85}%
\lstdefinestyle{StyleCommand}{%
style=StyleListingBasic, backgroundcolor=\color{mittelgrau}, prebreak=\mbox{\textbackslash{}}%
}
\lstnewenvironment{Befehl}[1][1] {\lstset{style=StyleCommand,linewidth=#1\linewidth}} {}%
\begin{document}
\begin{Befehl}
./robots-gui-helper
\end{Befehl}%
\end{document}

Resources