Custom paragraph command, prevent page break











up vote
1
down vote

favorite












I am using the book class to write a document that will have numbered paragraphs. Wanted the (auto-incremented) paragraph numbers to be bold and centred, then the text below, and the paragraph number to have a label so it can be referenced. Using other people's suggestions, I've got this function/command:



newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}


and the way I use it in the document is:



mypara{myreference}
This is a nice numbered paragraph. I don't want any braces around the paragraph body, if at all possible.


which is working nicely EXCEPT when I use it close to the bottom of the page, in which case it's possible for the bold paragraph number to be on one page, and the text of the paragraph to be on the next. Is it possible to prevent a page break like this? I'm using multicols{2} as well, if that's relevant. Any help appreciated.



Min. example:



documentclass[10pt]{book}
usepackage{multicol}
setlengthcolumnsep{1cm} % sets the distance between columns
usepackage{blindtext}

newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}

title{Minimum working example}

begin{document}
pagestyle{empty}
% main part of the document:

mainmatter
begin{multicols}{2}

mypara{ref1}
blindtext

mypara{ref2}
blindtext

mypara{ref3}
blindtext

mypara{ref4}
blindtext

end{multicols}
end{document}









share|improve this question
























  • Have you considered to change your label{#1} to also include something that will help you with easy identification? For example label{par:#1}. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.
    – Flexo013
    Jul 27 at 13:00










  • Thank you for this comment, I will consider doing that if I can get a viable fix to this problem to proceed with my document
    – tornadof3
    Jul 27 at 13:16










  • Is there a particular reason that you are using vfill? Since removing it results in this, which looks better IMO.
    – Flexo013
    Jul 27 at 13:30












  • Thanks. I was only using vfill because a previous google suggestion for this custom paragraph function had the vfill in. I agree it looks better without the vfill. Although on my live document I still have the same overall problem!
    – tornadof3
    Jul 27 at 13:34










  • Without vfill put the whole stuff in a box, eg.g., a parbox or a minipage, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.
    – Fran
    Oct 26 at 7:41















up vote
1
down vote

favorite












I am using the book class to write a document that will have numbered paragraphs. Wanted the (auto-incremented) paragraph numbers to be bold and centred, then the text below, and the paragraph number to have a label so it can be referenced. Using other people's suggestions, I've got this function/command:



newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}


and the way I use it in the document is:



mypara{myreference}
This is a nice numbered paragraph. I don't want any braces around the paragraph body, if at all possible.


which is working nicely EXCEPT when I use it close to the bottom of the page, in which case it's possible for the bold paragraph number to be on one page, and the text of the paragraph to be on the next. Is it possible to prevent a page break like this? I'm using multicols{2} as well, if that's relevant. Any help appreciated.



Min. example:



documentclass[10pt]{book}
usepackage{multicol}
setlengthcolumnsep{1cm} % sets the distance between columns
usepackage{blindtext}

newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}

title{Minimum working example}

begin{document}
pagestyle{empty}
% main part of the document:

mainmatter
begin{multicols}{2}

mypara{ref1}
blindtext

mypara{ref2}
blindtext

mypara{ref3}
blindtext

mypara{ref4}
blindtext

end{multicols}
end{document}









share|improve this question
























  • Have you considered to change your label{#1} to also include something that will help you with easy identification? For example label{par:#1}. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.
    – Flexo013
    Jul 27 at 13:00










  • Thank you for this comment, I will consider doing that if I can get a viable fix to this problem to proceed with my document
    – tornadof3
    Jul 27 at 13:16










  • Is there a particular reason that you are using vfill? Since removing it results in this, which looks better IMO.
    – Flexo013
    Jul 27 at 13:30












  • Thanks. I was only using vfill because a previous google suggestion for this custom paragraph function had the vfill in. I agree it looks better without the vfill. Although on my live document I still have the same overall problem!
    – tornadof3
    Jul 27 at 13:34










  • Without vfill put the whole stuff in a box, eg.g., a parbox or a minipage, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.
    – Fran
    Oct 26 at 7:41













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am using the book class to write a document that will have numbered paragraphs. Wanted the (auto-incremented) paragraph numbers to be bold and centred, then the text below, and the paragraph number to have a label so it can be referenced. Using other people's suggestions, I've got this function/command:



newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}


and the way I use it in the document is:



mypara{myreference}
This is a nice numbered paragraph. I don't want any braces around the paragraph body, if at all possible.


which is working nicely EXCEPT when I use it close to the bottom of the page, in which case it's possible for the bold paragraph number to be on one page, and the text of the paragraph to be on the next. Is it possible to prevent a page break like this? I'm using multicols{2} as well, if that's relevant. Any help appreciated.



Min. example:



documentclass[10pt]{book}
usepackage{multicol}
setlengthcolumnsep{1cm} % sets the distance between columns
usepackage{blindtext}

newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}

title{Minimum working example}

begin{document}
pagestyle{empty}
% main part of the document:

mainmatter
begin{multicols}{2}

mypara{ref1}
blindtext

mypara{ref2}
blindtext

mypara{ref3}
blindtext

mypara{ref4}
blindtext

end{multicols}
end{document}









share|improve this question















I am using the book class to write a document that will have numbered paragraphs. Wanted the (auto-incremented) paragraph numbers to be bold and centred, then the text below, and the paragraph number to have a label so it can be referenced. Using other people's suggestions, I've got this function/command:



newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}


and the way I use it in the document is:



mypara{myreference}
This is a nice numbered paragraph. I don't want any braces around the paragraph body, if at all possible.


which is working nicely EXCEPT when I use it close to the bottom of the page, in which case it's possible for the bold paragraph number to be on one page, and the text of the paragraph to be on the next. Is it possible to prevent a page break like this? I'm using multicols{2} as well, if that's relevant. Any help appreciated.



Min. example:



documentclass[10pt]{book}
usepackage{multicol}
setlengthcolumnsep{1cm} % sets the distance between columns
usepackage{blindtext}

newcounter{para}
newcommandmypara[1]{
parrefstepcounter{para}vfill
begin{center}textbf{thepara}end{center}label{#1}
}

title{Minimum working example}

begin{document}
pagestyle{empty}
% main part of the document:

mainmatter
begin{multicols}{2}

mypara{ref1}
blindtext

mypara{ref2}
blindtext

mypara{ref3}
blindtext

mypara{ref4}
blindtext

end{multicols}
end{document}






pdftex paragraphs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 27 at 13:32

























asked Jul 27 at 12:41









tornadof3

756




756












  • Have you considered to change your label{#1} to also include something that will help you with easy identification? For example label{par:#1}. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.
    – Flexo013
    Jul 27 at 13:00










  • Thank you for this comment, I will consider doing that if I can get a viable fix to this problem to proceed with my document
    – tornadof3
    Jul 27 at 13:16










  • Is there a particular reason that you are using vfill? Since removing it results in this, which looks better IMO.
    – Flexo013
    Jul 27 at 13:30












  • Thanks. I was only using vfill because a previous google suggestion for this custom paragraph function had the vfill in. I agree it looks better without the vfill. Although on my live document I still have the same overall problem!
    – tornadof3
    Jul 27 at 13:34










  • Without vfill put the whole stuff in a box, eg.g., a parbox or a minipage, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.
    – Fran
    Oct 26 at 7:41


















  • Have you considered to change your label{#1} to also include something that will help you with easy identification? For example label{par:#1}. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.
    – Flexo013
    Jul 27 at 13:00










  • Thank you for this comment, I will consider doing that if I can get a viable fix to this problem to proceed with my document
    – tornadof3
    Jul 27 at 13:16










  • Is there a particular reason that you are using vfill? Since removing it results in this, which looks better IMO.
    – Flexo013
    Jul 27 at 13:30












  • Thanks. I was only using vfill because a previous google suggestion for this custom paragraph function had the vfill in. I agree it looks better without the vfill. Although on my live document I still have the same overall problem!
    – tornadof3
    Jul 27 at 13:34










  • Without vfill put the whole stuff in a box, eg.g., a parbox or a minipage, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.
    – Fran
    Oct 26 at 7:41
















Have you considered to change your label{#1} to also include something that will help you with easy identification? For example label{par:#1}. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.
– Flexo013
Jul 27 at 13:00




Have you considered to change your label{#1} to also include something that will help you with easy identification? For example label{par:#1}. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.
– Flexo013
Jul 27 at 13:00












Thank you for this comment, I will consider doing that if I can get a viable fix to this problem to proceed with my document
– tornadof3
Jul 27 at 13:16




Thank you for this comment, I will consider doing that if I can get a viable fix to this problem to proceed with my document
– tornadof3
Jul 27 at 13:16












Is there a particular reason that you are using vfill? Since removing it results in this, which looks better IMO.
– Flexo013
Jul 27 at 13:30






Is there a particular reason that you are using vfill? Since removing it results in this, which looks better IMO.
– Flexo013
Jul 27 at 13:30














Thanks. I was only using vfill because a previous google suggestion for this custom paragraph function had the vfill in. I agree it looks better without the vfill. Although on my live document I still have the same overall problem!
– tornadof3
Jul 27 at 13:34




Thanks. I was only using vfill because a previous google suggestion for this custom paragraph function had the vfill in. I agree it looks better without the vfill. Although on my live document I still have the same overall problem!
– tornadof3
Jul 27 at 13:34












Without vfill put the whole stuff in a box, eg.g., a parbox or a minipage, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.
– Fran
Oct 26 at 7:41




Without vfill put the whole stuff in a box, eg.g., a parbox or a minipage, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.
– Fran
Oct 26 at 7:41










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Removing the vfill as pointed by @Flexo013 actually fixes your local problem.
I would however provide another solution, that IMO is more efficient.



First, if you don use chapter (and have no frontmatter) you definitely don't need the features of the book class. Second, if you wish to be able to produce a TOC and bookmarks, your para won't do the job.



Let me switch to article and modify the top-level sectioning command section by the use of a sinle line titleformat from titlesec package.
The MWE :



documentclass[10pt]{article}
usepackage[utf8]{inputenc}
usepackage{multicol}
setlengthcolumnsep{1cm} % sets the distance between columns
usepackage{blindtext}
usepackage[explicit]{titlesec}
usepackage{hyperref}
pagestyle{empty}

begin{document}
begin{multicols}{2}

tableofcontents

makeatletter
titleformat{section}[block]{centeringbfseries}{thesection}{0pt}{@gobble{#1}}[label{par:#1}]
makeatother

section{foo}
blindtext

section{bar}
In Sref{par:foo} we said that ldots

section{foo2}
blindtext

section{bar2}
In §,ref{par:foo2} we will say that ldots

section{foo3}
blindtext

section{bar3}
blindtext

end{multicols}
end{document}





share|improve this answer





















  • Thank you. I will try this and see how it works
    – tornadof3
    Jul 27 at 17:59










  • In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
    – Jhor
    Jul 27 at 18:44




















up vote
0
down vote













You can use the standard sectioning mechanism, suitably adapted.



documentclass[10pt]{book}
usepackage{multicol}
setlengthcolumnsep{1cm} % sets the distance between columns
usepackage{blindtext}

makeatletter
newcounter{para}
newcommandmypara[1]{%
@startsection{para}{1}{z@}%
{-topsep}%
{topsep}%
{normalfontbfseriescentering}%
{}label{#1}%
}
newcommand{myparamark}[1]{}
renewcommand{@seccntformat}[1]{%
ifcsname format#1endcsname
csname format#1endcsname
else
csname the#1endcsnamequad
fi
}
newcommand{formatpara}{thepara}
makeatother


begin{document}

title{Minimum working example}
pagestyle{empty}

% main part of the document:

mainmatter

begin{multicols}{2}

mypara{ref1}
%A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more\
A line more

blindtext

mypara{ref2}
blindtext

mypara{ref3}
blindtext

mypara{ref4}
blindtext

end{multicols}

end{document}


You can check that uncommenting the first A line more, section 4 will be pushed to the next page.






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f443425%2fcustom-paragraph-command-prevent-page-break%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Removing the vfill as pointed by @Flexo013 actually fixes your local problem.
    I would however provide another solution, that IMO is more efficient.



    First, if you don use chapter (and have no frontmatter) you definitely don't need the features of the book class. Second, if you wish to be able to produce a TOC and bookmarks, your para won't do the job.



    Let me switch to article and modify the top-level sectioning command section by the use of a sinle line titleformat from titlesec package.
    The MWE :



    documentclass[10pt]{article}
    usepackage[utf8]{inputenc}
    usepackage{multicol}
    setlengthcolumnsep{1cm} % sets the distance between columns
    usepackage{blindtext}
    usepackage[explicit]{titlesec}
    usepackage{hyperref}
    pagestyle{empty}

    begin{document}
    begin{multicols}{2}

    tableofcontents

    makeatletter
    titleformat{section}[block]{centeringbfseries}{thesection}{0pt}{@gobble{#1}}[label{par:#1}]
    makeatother

    section{foo}
    blindtext

    section{bar}
    In Sref{par:foo} we said that ldots

    section{foo2}
    blindtext

    section{bar2}
    In §,ref{par:foo2} we will say that ldots

    section{foo3}
    blindtext

    section{bar3}
    blindtext

    end{multicols}
    end{document}





    share|improve this answer





















    • Thank you. I will try this and see how it works
      – tornadof3
      Jul 27 at 17:59










    • In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
      – Jhor
      Jul 27 at 18:44

















    up vote
    0
    down vote













    Removing the vfill as pointed by @Flexo013 actually fixes your local problem.
    I would however provide another solution, that IMO is more efficient.



    First, if you don use chapter (and have no frontmatter) you definitely don't need the features of the book class. Second, if you wish to be able to produce a TOC and bookmarks, your para won't do the job.



    Let me switch to article and modify the top-level sectioning command section by the use of a sinle line titleformat from titlesec package.
    The MWE :



    documentclass[10pt]{article}
    usepackage[utf8]{inputenc}
    usepackage{multicol}
    setlengthcolumnsep{1cm} % sets the distance between columns
    usepackage{blindtext}
    usepackage[explicit]{titlesec}
    usepackage{hyperref}
    pagestyle{empty}

    begin{document}
    begin{multicols}{2}

    tableofcontents

    makeatletter
    titleformat{section}[block]{centeringbfseries}{thesection}{0pt}{@gobble{#1}}[label{par:#1}]
    makeatother

    section{foo}
    blindtext

    section{bar}
    In Sref{par:foo} we said that ldots

    section{foo2}
    blindtext

    section{bar2}
    In §,ref{par:foo2} we will say that ldots

    section{foo3}
    blindtext

    section{bar3}
    blindtext

    end{multicols}
    end{document}





    share|improve this answer





















    • Thank you. I will try this and see how it works
      – tornadof3
      Jul 27 at 17:59










    • In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
      – Jhor
      Jul 27 at 18:44















    up vote
    0
    down vote










    up vote
    0
    down vote









    Removing the vfill as pointed by @Flexo013 actually fixes your local problem.
    I would however provide another solution, that IMO is more efficient.



    First, if you don use chapter (and have no frontmatter) you definitely don't need the features of the book class. Second, if you wish to be able to produce a TOC and bookmarks, your para won't do the job.



    Let me switch to article and modify the top-level sectioning command section by the use of a sinle line titleformat from titlesec package.
    The MWE :



    documentclass[10pt]{article}
    usepackage[utf8]{inputenc}
    usepackage{multicol}
    setlengthcolumnsep{1cm} % sets the distance between columns
    usepackage{blindtext}
    usepackage[explicit]{titlesec}
    usepackage{hyperref}
    pagestyle{empty}

    begin{document}
    begin{multicols}{2}

    tableofcontents

    makeatletter
    titleformat{section}[block]{centeringbfseries}{thesection}{0pt}{@gobble{#1}}[label{par:#1}]
    makeatother

    section{foo}
    blindtext

    section{bar}
    In Sref{par:foo} we said that ldots

    section{foo2}
    blindtext

    section{bar2}
    In §,ref{par:foo2} we will say that ldots

    section{foo3}
    blindtext

    section{bar3}
    blindtext

    end{multicols}
    end{document}





    share|improve this answer












    Removing the vfill as pointed by @Flexo013 actually fixes your local problem.
    I would however provide another solution, that IMO is more efficient.



    First, if you don use chapter (and have no frontmatter) you definitely don't need the features of the book class. Second, if you wish to be able to produce a TOC and bookmarks, your para won't do the job.



    Let me switch to article and modify the top-level sectioning command section by the use of a sinle line titleformat from titlesec package.
    The MWE :



    documentclass[10pt]{article}
    usepackage[utf8]{inputenc}
    usepackage{multicol}
    setlengthcolumnsep{1cm} % sets the distance between columns
    usepackage{blindtext}
    usepackage[explicit]{titlesec}
    usepackage{hyperref}
    pagestyle{empty}

    begin{document}
    begin{multicols}{2}

    tableofcontents

    makeatletter
    titleformat{section}[block]{centeringbfseries}{thesection}{0pt}{@gobble{#1}}[label{par:#1}]
    makeatother

    section{foo}
    blindtext

    section{bar}
    In Sref{par:foo} we said that ldots

    section{foo2}
    blindtext

    section{bar2}
    In §,ref{par:foo2} we will say that ldots

    section{foo3}
    blindtext

    section{bar3}
    blindtext

    end{multicols}
    end{document}






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 27 at 16:56









    Jhor

    2,0761014




    2,0761014












    • Thank you. I will try this and see how it works
      – tornadof3
      Jul 27 at 17:59










    • In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
      – Jhor
      Jul 27 at 18:44




















    • Thank you. I will try this and see how it works
      – tornadof3
      Jul 27 at 17:59










    • In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
      – Jhor
      Jul 27 at 18:44


















    Thank you. I will try this and see how it works
    – tornadof3
    Jul 27 at 17:59




    Thank you. I will try this and see how it works
    – tornadof3
    Jul 27 at 17:59












    In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
    – Jhor
    Jul 27 at 18:44






    In this answer I didn't really addressed the problem of pagebreak between title (in your case the number) and the body of the paragraph. In principle, the standard mechanism of LaTeX for handling the sectioning commend should avoid 90% of such breaks. If some still occur, one could tweak the penalties.
    – Jhor
    Jul 27 at 18:44












    up vote
    0
    down vote













    You can use the standard sectioning mechanism, suitably adapted.



    documentclass[10pt]{book}
    usepackage{multicol}
    setlengthcolumnsep{1cm} % sets the distance between columns
    usepackage{blindtext}

    makeatletter
    newcounter{para}
    newcommandmypara[1]{%
    @startsection{para}{1}{z@}%
    {-topsep}%
    {topsep}%
    {normalfontbfseriescentering}%
    {}label{#1}%
    }
    newcommand{myparamark}[1]{}
    renewcommand{@seccntformat}[1]{%
    ifcsname format#1endcsname
    csname format#1endcsname
    else
    csname the#1endcsnamequad
    fi
    }
    newcommand{formatpara}{thepara}
    makeatother


    begin{document}

    title{Minimum working example}
    pagestyle{empty}

    % main part of the document:

    mainmatter

    begin{multicols}{2}

    mypara{ref1}
    %A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more\
    A line more

    blindtext

    mypara{ref2}
    blindtext

    mypara{ref3}
    blindtext

    mypara{ref4}
    blindtext

    end{multicols}

    end{document}


    You can check that uncommenting the first A line more, section 4 will be pushed to the next page.






    share|improve this answer

























      up vote
      0
      down vote













      You can use the standard sectioning mechanism, suitably adapted.



      documentclass[10pt]{book}
      usepackage{multicol}
      setlengthcolumnsep{1cm} % sets the distance between columns
      usepackage{blindtext}

      makeatletter
      newcounter{para}
      newcommandmypara[1]{%
      @startsection{para}{1}{z@}%
      {-topsep}%
      {topsep}%
      {normalfontbfseriescentering}%
      {}label{#1}%
      }
      newcommand{myparamark}[1]{}
      renewcommand{@seccntformat}[1]{%
      ifcsname format#1endcsname
      csname format#1endcsname
      else
      csname the#1endcsnamequad
      fi
      }
      newcommand{formatpara}{thepara}
      makeatother


      begin{document}

      title{Minimum working example}
      pagestyle{empty}

      % main part of the document:

      mainmatter

      begin{multicols}{2}

      mypara{ref1}
      %A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more\
      A line more

      blindtext

      mypara{ref2}
      blindtext

      mypara{ref3}
      blindtext

      mypara{ref4}
      blindtext

      end{multicols}

      end{document}


      You can check that uncommenting the first A line more, section 4 will be pushed to the next page.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You can use the standard sectioning mechanism, suitably adapted.



        documentclass[10pt]{book}
        usepackage{multicol}
        setlengthcolumnsep{1cm} % sets the distance between columns
        usepackage{blindtext}

        makeatletter
        newcounter{para}
        newcommandmypara[1]{%
        @startsection{para}{1}{z@}%
        {-topsep}%
        {topsep}%
        {normalfontbfseriescentering}%
        {}label{#1}%
        }
        newcommand{myparamark}[1]{}
        renewcommand{@seccntformat}[1]{%
        ifcsname format#1endcsname
        csname format#1endcsname
        else
        csname the#1endcsnamequad
        fi
        }
        newcommand{formatpara}{thepara}
        makeatother


        begin{document}

        title{Minimum working example}
        pagestyle{empty}

        % main part of the document:

        mainmatter

        begin{multicols}{2}

        mypara{ref1}
        %A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more

        blindtext

        mypara{ref2}
        blindtext

        mypara{ref3}
        blindtext

        mypara{ref4}
        blindtext

        end{multicols}

        end{document}


        You can check that uncommenting the first A line more, section 4 will be pushed to the next page.






        share|improve this answer












        You can use the standard sectioning mechanism, suitably adapted.



        documentclass[10pt]{book}
        usepackage{multicol}
        setlengthcolumnsep{1cm} % sets the distance between columns
        usepackage{blindtext}

        makeatletter
        newcounter{para}
        newcommandmypara[1]{%
        @startsection{para}{1}{z@}%
        {-topsep}%
        {topsep}%
        {normalfontbfseriescentering}%
        {}label{#1}%
        }
        newcommand{myparamark}[1]{}
        renewcommand{@seccntformat}[1]{%
        ifcsname format#1endcsname
        csname format#1endcsname
        else
        csname the#1endcsnamequad
        fi
        }
        newcommand{formatpara}{thepara}
        makeatother


        begin{document}

        title{Minimum working example}
        pagestyle{empty}

        % main part of the document:

        mainmatter

        begin{multicols}{2}

        mypara{ref1}
        %A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more\
        A line more

        blindtext

        mypara{ref2}
        blindtext

        mypara{ref3}
        blindtext

        mypara{ref4}
        blindtext

        end{multicols}

        end{document}


        You can check that uncommenting the first A line more, section 4 will be pushed to the next page.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 58 mins ago









        egreg

        699k8518613132




        699k8518613132






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f443425%2fcustom-paragraph-command-prevent-page-break%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Futebolista

            Jornalista