How in the world do I place line of text EVENLY between two horizontal tikz lines?Best choice between using \ or leaving space after each paragraph to end the paragraphVertical space between horizontal linesAdjust spacing between text and horizontal ruletikz apply fill between two linesHow to define the default vertical distance between nodes?Connecting two nodes with horizontal-vertical-horizontal line in tikzTikz: how to draw a horizontal line between 2 nodesDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themCenter text between horizontal linesTikZ node: How to decrease vertical space between two lines of text?

Meaning of "legitimate" in Carl Jung's quote "Neurosis is always a substitute for legitimate suffering."

Should generated documentation be stored in a Git repository?

God-Pharaoh's Statue and Finale Of Promise

Formal Definition of Dot Product

Capital gains on stocks sold to take initial investment off the table

Why does SSL Labs now consider CBC suites weak?

How to continually let my readers know what time it is in my story, in an organic way?

equation in minipage can't be numbered in the same line

Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?

Could there be something like aerobatic smoke trails in the vacuum of space?

Single word that parallels "Recent" when discussing the near future

Word for "activity tracker" or "smart bracelet"

What is Feeblemind's effect on Ability Score Improvements?

the correct order of manual install WP and SSL on server

Why did the soldiers of the North disobey Jon?

What was Varys trying to do at the beginning of S08E05?

Wireless headphones interfere with Wi-Fi signal on laptop

Were any toxic metals used in the International Space Station?

How to make a not so good looking person more appealing?

Is there any good reason to write "it is easy to see"?

How to not get blinded by an attack at dawn

Why do galaxies collide

Why can't I share a one use code with anyone else?

Why commonly or frequently used fonts sizes are even numbers like 10px, 12px, 16px, 24px, or 32px?



How in the world do I place line of text EVENLY between two horizontal tikz lines?


Best choice between using \ or leaving space after each paragraph to end the paragraphVertical space between horizontal linesAdjust spacing between text and horizontal ruletikz apply fill between two linesHow to define the default vertical distance between nodes?Connecting two nodes with horizontal-vertical-horizontal line in tikzTikz: how to draw a horizontal line between 2 nodesDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themCenter text between horizontal linesTikZ node: How to decrease vertical space between two lines of text?













5















Vertical spacing is killing me lately. First I had to learn how to get rid of automatically-generated vertical-spacing after center environment because it was off (partopsep+topsep), then I had to learn how to get rid of automatically-generated vertical-spacing after equation or [] environments (set belowdisplayskip and belowdisplayshortskip to 0) because it was off. Now I have difficulties with positioning line of text EVENLY between two horizontal lines drawn with tikz. This is crazy! (could it be more simple, like HTML?)



So I am counting on you to help me out with this.



documentclass[border=5mm,varwidth=150mm]standalone

usepackagetikz

begindocument

begintikzpicture
path[draw](0,0)--(textwidth,0);
endtikzpicture\

hello\

begintikzpicture
path[draw=red](0,0)--(textwidth,0);
endtikzpicture

enddocument`




Obviously, the text should be slightly lower.










share|improve this question

















  • 1





    The baselines are evenly spaced. You need to decide where you want things relative to the baselines.

    – John Kormylo
    May 4 at 3:31






  • 1





    Speaking of your vertical spacing questions, it's not clear to me that you need to be going to all of your trouble. What is it that you are trying to do? Your examples haven't been very clear, and seem suggest an XY problem to me. At the least, we should figure out how to appropriately use the existing environments and see what that vertical spacing would be. Then we can figure out why TeX doesn't have the vertical spacing you'd like.

    – Teepeemm
    May 4 at 13:19











  • @Teepeemm, I need to be able to place one or more lines of text or vertical-mode math-expression between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I also need spacing before top line and after bottom line to disappear so that next top line lays on top of previous bottom line. What makes it more complicated is that I sometimes use center and tikzpicture environments to enclose text and math which need to be placed between the lines.

    – bp2017
    May 4 at 15:33












  • But it's not clear (at least to me) that you need to do the things you say you need to do. Could you show us a simplified example that has the improper spacing? I suppose I could conceive of a situation where I might want to do the things you are trying to do, but I could also see it being possible that you are getting bad spacing because you're misusing some commands.

    – Teepeemm
    May 4 at 21:39











  • @Teepeemm, you can take a look at my new question (tex.stackexchange.com/q/489237/141768).

    – bp2017
    May 5 at 1:14















5















Vertical spacing is killing me lately. First I had to learn how to get rid of automatically-generated vertical-spacing after center environment because it was off (partopsep+topsep), then I had to learn how to get rid of automatically-generated vertical-spacing after equation or [] environments (set belowdisplayskip and belowdisplayshortskip to 0) because it was off. Now I have difficulties with positioning line of text EVENLY between two horizontal lines drawn with tikz. This is crazy! (could it be more simple, like HTML?)



So I am counting on you to help me out with this.



documentclass[border=5mm,varwidth=150mm]standalone

usepackagetikz

begindocument

begintikzpicture
path[draw](0,0)--(textwidth,0);
endtikzpicture\

hello\

begintikzpicture
path[draw=red](0,0)--(textwidth,0);
endtikzpicture

enddocument`




Obviously, the text should be slightly lower.










share|improve this question

















  • 1





    The baselines are evenly spaced. You need to decide where you want things relative to the baselines.

    – John Kormylo
    May 4 at 3:31






  • 1





    Speaking of your vertical spacing questions, it's not clear to me that you need to be going to all of your trouble. What is it that you are trying to do? Your examples haven't been very clear, and seem suggest an XY problem to me. At the least, we should figure out how to appropriately use the existing environments and see what that vertical spacing would be. Then we can figure out why TeX doesn't have the vertical spacing you'd like.

    – Teepeemm
    May 4 at 13:19











  • @Teepeemm, I need to be able to place one or more lines of text or vertical-mode math-expression between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I also need spacing before top line and after bottom line to disappear so that next top line lays on top of previous bottom line. What makes it more complicated is that I sometimes use center and tikzpicture environments to enclose text and math which need to be placed between the lines.

    – bp2017
    May 4 at 15:33












  • But it's not clear (at least to me) that you need to do the things you say you need to do. Could you show us a simplified example that has the improper spacing? I suppose I could conceive of a situation where I might want to do the things you are trying to do, but I could also see it being possible that you are getting bad spacing because you're misusing some commands.

    – Teepeemm
    May 4 at 21:39











  • @Teepeemm, you can take a look at my new question (tex.stackexchange.com/q/489237/141768).

    – bp2017
    May 5 at 1:14













5












5








5


1






Vertical spacing is killing me lately. First I had to learn how to get rid of automatically-generated vertical-spacing after center environment because it was off (partopsep+topsep), then I had to learn how to get rid of automatically-generated vertical-spacing after equation or [] environments (set belowdisplayskip and belowdisplayshortskip to 0) because it was off. Now I have difficulties with positioning line of text EVENLY between two horizontal lines drawn with tikz. This is crazy! (could it be more simple, like HTML?)



So I am counting on you to help me out with this.



documentclass[border=5mm,varwidth=150mm]standalone

usepackagetikz

begindocument

begintikzpicture
path[draw](0,0)--(textwidth,0);
endtikzpicture\

hello\

begintikzpicture
path[draw=red](0,0)--(textwidth,0);
endtikzpicture

enddocument`




Obviously, the text should be slightly lower.










share|improve this question














Vertical spacing is killing me lately. First I had to learn how to get rid of automatically-generated vertical-spacing after center environment because it was off (partopsep+topsep), then I had to learn how to get rid of automatically-generated vertical-spacing after equation or [] environments (set belowdisplayskip and belowdisplayshortskip to 0) because it was off. Now I have difficulties with positioning line of text EVENLY between two horizontal lines drawn with tikz. This is crazy! (could it be more simple, like HTML?)



So I am counting on you to help me out with this.



documentclass[border=5mm,varwidth=150mm]standalone

usepackagetikz

begindocument

begintikzpicture
path[draw](0,0)--(textwidth,0);
endtikzpicture\

hello\

begintikzpicture
path[draw=red](0,0)--(textwidth,0);
endtikzpicture

enddocument`




Obviously, the text should be slightly lower.







tikz-pgf spacing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 4 at 1:50









bp2017bp2017

915116




915116







  • 1





    The baselines are evenly spaced. You need to decide where you want things relative to the baselines.

    – John Kormylo
    May 4 at 3:31






  • 1





    Speaking of your vertical spacing questions, it's not clear to me that you need to be going to all of your trouble. What is it that you are trying to do? Your examples haven't been very clear, and seem suggest an XY problem to me. At the least, we should figure out how to appropriately use the existing environments and see what that vertical spacing would be. Then we can figure out why TeX doesn't have the vertical spacing you'd like.

    – Teepeemm
    May 4 at 13:19











  • @Teepeemm, I need to be able to place one or more lines of text or vertical-mode math-expression between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I also need spacing before top line and after bottom line to disappear so that next top line lays on top of previous bottom line. What makes it more complicated is that I sometimes use center and tikzpicture environments to enclose text and math which need to be placed between the lines.

    – bp2017
    May 4 at 15:33












  • But it's not clear (at least to me) that you need to do the things you say you need to do. Could you show us a simplified example that has the improper spacing? I suppose I could conceive of a situation where I might want to do the things you are trying to do, but I could also see it being possible that you are getting bad spacing because you're misusing some commands.

    – Teepeemm
    May 4 at 21:39











  • @Teepeemm, you can take a look at my new question (tex.stackexchange.com/q/489237/141768).

    – bp2017
    May 5 at 1:14












  • 1





    The baselines are evenly spaced. You need to decide where you want things relative to the baselines.

    – John Kormylo
    May 4 at 3:31






  • 1





    Speaking of your vertical spacing questions, it's not clear to me that you need to be going to all of your trouble. What is it that you are trying to do? Your examples haven't been very clear, and seem suggest an XY problem to me. At the least, we should figure out how to appropriately use the existing environments and see what that vertical spacing would be. Then we can figure out why TeX doesn't have the vertical spacing you'd like.

    – Teepeemm
    May 4 at 13:19











  • @Teepeemm, I need to be able to place one or more lines of text or vertical-mode math-expression between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I also need spacing before top line and after bottom line to disappear so that next top line lays on top of previous bottom line. What makes it more complicated is that I sometimes use center and tikzpicture environments to enclose text and math which need to be placed between the lines.

    – bp2017
    May 4 at 15:33












  • But it's not clear (at least to me) that you need to do the things you say you need to do. Could you show us a simplified example that has the improper spacing? I suppose I could conceive of a situation where I might want to do the things you are trying to do, but I could also see it being possible that you are getting bad spacing because you're misusing some commands.

    – Teepeemm
    May 4 at 21:39











  • @Teepeemm, you can take a look at my new question (tex.stackexchange.com/q/489237/141768).

    – bp2017
    May 5 at 1:14







1




1





The baselines are evenly spaced. You need to decide where you want things relative to the baselines.

– John Kormylo
May 4 at 3:31





The baselines are evenly spaced. You need to decide where you want things relative to the baselines.

– John Kormylo
May 4 at 3:31




1




1





Speaking of your vertical spacing questions, it's not clear to me that you need to be going to all of your trouble. What is it that you are trying to do? Your examples haven't been very clear, and seem suggest an XY problem to me. At the least, we should figure out how to appropriately use the existing environments and see what that vertical spacing would be. Then we can figure out why TeX doesn't have the vertical spacing you'd like.

– Teepeemm
May 4 at 13:19





Speaking of your vertical spacing questions, it's not clear to me that you need to be going to all of your trouble. What is it that you are trying to do? Your examples haven't been very clear, and seem suggest an XY problem to me. At the least, we should figure out how to appropriately use the existing environments and see what that vertical spacing would be. Then we can figure out why TeX doesn't have the vertical spacing you'd like.

– Teepeemm
May 4 at 13:19













@Teepeemm, I need to be able to place one or more lines of text or vertical-mode math-expression between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I also need spacing before top line and after bottom line to disappear so that next top line lays on top of previous bottom line. What makes it more complicated is that I sometimes use center and tikzpicture environments to enclose text and math which need to be placed between the lines.

– bp2017
May 4 at 15:33






@Teepeemm, I need to be able to place one or more lines of text or vertical-mode math-expression between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I also need spacing before top line and after bottom line to disappear so that next top line lays on top of previous bottom line. What makes it more complicated is that I sometimes use center and tikzpicture environments to enclose text and math which need to be placed between the lines.

– bp2017
May 4 at 15:33














But it's not clear (at least to me) that you need to do the things you say you need to do. Could you show us a simplified example that has the improper spacing? I suppose I could conceive of a situation where I might want to do the things you are trying to do, but I could also see it being possible that you are getting bad spacing because you're misusing some commands.

– Teepeemm
May 4 at 21:39





But it's not clear (at least to me) that you need to do the things you say you need to do. Could you show us a simplified example that has the improper spacing? I suppose I could conceive of a situation where I might want to do the things you are trying to do, but I could also see it being possible that you are getting bad spacing because you're misusing some commands.

– Teepeemm
May 4 at 21:39













@Teepeemm, you can take a look at my new question (tex.stackexchange.com/q/489237/141768).

– bp2017
May 5 at 1:14





@Teepeemm, you can take a look at my new question (tex.stackexchange.com/q/489237/141768).

– bp2017
May 5 at 1:14










5 Answers
5






active

oldest

votes


















4














You shouldn't use \ to end a paragraph and the arguably simplest way is to do everything with TikZ.



documentclass[border=5mm,varwidth=150mm]standalone
usepackagetikz
newcounterbpnode
tikzsetevery node/.append style=/utils/exec=stepcounterbpnode,
alias=bpnode-numbervaluebpnode
begindocument
begintikzpicture
node[outer sep=0pt,inner sep=0pt,text width=textwidth,align=left] (txt)
hello hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello hello
hello hello hello hello hello hello hello hello hello;
path[draw]([yshift=1em]txt.north west)--++(textwidth,0);
path[draw=red]([yshift=-1em]txt.south west)--++(textwidth,0);
%draw (bpnode-1) -- ++ (2,0);
typeoutthetextwidth
endtikzpicture
enddocument


enter image description here



Here is a "quick and dirty" proposal using the baseline key.



documentclass[border=5mm,varwidth=150mm]standalone

usepackagetikz

begindocument

begintikzpicture[baseline=-0.6ex]
path[draw](0,0)--(textwidth,0);
endtikzpicturepar
noindent%
hellopar
noindent%
begintikzpicture[baseline=-0.6ex]
path[draw=red](0,0)--(textwidth,0);
endtikzpicture

enddocument


enter image description here






share|improve this answer




















  • 1





    @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

    – marmot
    May 4 at 2:31






  • 1





    @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

    – marmot
    May 4 at 3:31







  • 1





    @bp2017 You should literally never use \ to end a paragraph..

    – L. F.
    May 4 at 5:24







  • 1





    @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

    – marmot
    May 4 at 5:53











  • the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

    – David Carlisle
    May 4 at 8:03


















2














Using TikZ, I would put the text in a node of the desired width, then use the node anchors do draw the lines.



documentclass[border=5mm,varwidth=150mm]standalone
usepackagetikz
begindocument
begintikzpicture
node(a)[minimum width=linewidth,text width=linewidth]hello;
draw(a.north west)--(a.north east);
draw[red](a.south west)--(a.south east);
endtikzpicture
enddocument


enter image description here



Here's a non-TikZ answer just to show another approach.



documentclass[border=5mm,varwidth=150mm]standalone
usepackagebooktabs
usepackagecolortbl
usepackagetabularx
begindocument
begintabularxlinewidth@l@
midrule
hello\
arrayrulecolorredmidrule
endtabularx
enddocument


enter image description here






share|improve this answer






























    2














    This uses a parbox and vfill. The baselines are ignored in this case, since the baseline of the parbox is more than baselineskip from either above or below, so instead LaTeX adds a gap of lineskip (1pt). Inside the parbox, the vfills expand to the same size. The same effect is achieved by using [c] instead of [s] and vfill, but I wanted to show how it was done.



    documentclass[border=5mm,varwidth=150mm]standalone
    usepackagetikz
    begindocument

    noindentbegintikzpicture
    path[draw](0,0)--(textwidth,0);
    endtikzpicture\
    parbox[c][3baselineskip][s]textwidthvfill
    hello
    vfill\
    begintikzpicture
    path[draw=red](0,0)--(textwidth,0);
    endtikzpicture

    enddocument



    This uses raisebox to move the text relative to the baseline. The rule shows where the baseline is located.



    documentclass[border=5mm,varwidth=150mm]standalone
    usepackagetikz
    begindocument

    begintikzpicture
    path[draw](0,0)--(textwidth,0);
    endtikzpicture\
    raiseboxdimexpr 0.5depth-0.5heightHellow
    rule1em0.5pt
    raiseboxdimexpr 0.5depth-0.5heightpygmy\
    begintikzpicture
    path[draw=red](0,0)--(textwidth,0);
    endtikzpicture

    enddocument


    demo






    share|improve this answer
































      1














      Why use TikZ at all?



      documentclassarticle

      usepackagexcolor

      begindocument

      hrule
      vspace1ex
      noindent
      hello
      vspace1ex
      colorredhrule

      enddocument`


      MWE output



      As mentioned by others, if you really want to use TikZ you should put the text in a node.




      If you want to use this a lot in your document you should of course make it a macro:



      documentclassarticle

      usepackagexparse
      usepackagetikz

      NewDocumentCommandmymacroO.5baselineskip O.25baselineskip +m o Ored%
      vspace#2%
      IfValueT#4color#4hrule%
      vspace#1%
      noindent #3%
      vspace#1%
      color#5hrule%
      vspace#2%


      NewDocumentCommandmytikzmacroO.5baselineskip O.25baselineskip +m O O%
      parnoindent
      begintikzpicture [line cap=butt]
      node [outer sep=0pt, inner sep=0pt, inner ysep=#1, text width=textwidth-.4pt] (txt) #3;
      draw [#4] (txt.north west) -- (txt.north east);
      draw [red, #5] (txt.south west) -- (txt.south east);
      clip ([yshift=-#2] current bounding box.south west) rectangle ([yshift=#2] current bounding box.north east);
      endtikzpicture%


      begindocument

      mymacroHello World!

      mytikzmacroAdieu World!

      enddocument


      macro MWE output




      If what you are trying to do is just putting some frames around text, you might also want to have a look at packages designed for that purpose, like mdframed or tcolorbox.






      share|improve this answer

























      • I've been told hrule breaks spacing in a bad way (better use something else?).

        – bp2017
        May 4 at 15:27












      • By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

        – bp2017
        May 4 at 15:43











      • One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

        – schtandard
        May 5 at 0:00











      • You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

        – schtandard
        May 5 at 0:01


















      0














      Check this out.



      documentclass[border=5mm,varwidth=150mm]standalone

      usepackagetikz

      begindocument

      begintikzpicture
      path[draw](0,0)--(textwidth,0);
      endtikzpicture

      nointerlineskipvspace5pt
      hello xy % or use par to replace following blank line

      nointerlineskipvspace5pt
      begintikzpicture
      path[draw=red](0,0)--(textwidth,0);
      endtikzpicture

      enddocument







      share|improve this answer


















      • 1





        in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

        – David Carlisle
        May 4 at 8:05











      • @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

        – bp2017
        May 4 at 15:25












      • @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

        – bp2017
        May 4 at 15:46












      • you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

        – David Carlisle
        May 4 at 16:35











      • @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

        – bp2017
        May 5 at 1:15












      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',
      autoActivateHeartbeat: false,
      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%2f489074%2fhow-in-the-world-do-i-place-line-of-text-evenly-between-two-horizontal-tikz-line%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      You shouldn't use \ to end a paragraph and the arguably simplest way is to do everything with TikZ.



      documentclass[border=5mm,varwidth=150mm]standalone
      usepackagetikz
      newcounterbpnode
      tikzsetevery node/.append style=/utils/exec=stepcounterbpnode,
      alias=bpnode-numbervaluebpnode
      begindocument
      begintikzpicture
      node[outer sep=0pt,inner sep=0pt,text width=textwidth,align=left] (txt)
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello;
      path[draw]([yshift=1em]txt.north west)--++(textwidth,0);
      path[draw=red]([yshift=-1em]txt.south west)--++(textwidth,0);
      %draw (bpnode-1) -- ++ (2,0);
      typeoutthetextwidth
      endtikzpicture
      enddocument


      enter image description here



      Here is a "quick and dirty" proposal using the baseline key.



      documentclass[border=5mm,varwidth=150mm]standalone

      usepackagetikz

      begindocument

      begintikzpicture[baseline=-0.6ex]
      path[draw](0,0)--(textwidth,0);
      endtikzpicturepar
      noindent%
      hellopar
      noindent%
      begintikzpicture[baseline=-0.6ex]
      path[draw=red](0,0)--(textwidth,0);
      endtikzpicture

      enddocument


      enter image description here






      share|improve this answer




















      • 1





        @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

        – marmot
        May 4 at 2:31






      • 1





        @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

        – marmot
        May 4 at 3:31







      • 1





        @bp2017 You should literally never use \ to end a paragraph..

        – L. F.
        May 4 at 5:24







      • 1





        @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

        – marmot
        May 4 at 5:53











      • the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

        – David Carlisle
        May 4 at 8:03















      4














      You shouldn't use \ to end a paragraph and the arguably simplest way is to do everything with TikZ.



      documentclass[border=5mm,varwidth=150mm]standalone
      usepackagetikz
      newcounterbpnode
      tikzsetevery node/.append style=/utils/exec=stepcounterbpnode,
      alias=bpnode-numbervaluebpnode
      begindocument
      begintikzpicture
      node[outer sep=0pt,inner sep=0pt,text width=textwidth,align=left] (txt)
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello;
      path[draw]([yshift=1em]txt.north west)--++(textwidth,0);
      path[draw=red]([yshift=-1em]txt.south west)--++(textwidth,0);
      %draw (bpnode-1) -- ++ (2,0);
      typeoutthetextwidth
      endtikzpicture
      enddocument


      enter image description here



      Here is a "quick and dirty" proposal using the baseline key.



      documentclass[border=5mm,varwidth=150mm]standalone

      usepackagetikz

      begindocument

      begintikzpicture[baseline=-0.6ex]
      path[draw](0,0)--(textwidth,0);
      endtikzpicturepar
      noindent%
      hellopar
      noindent%
      begintikzpicture[baseline=-0.6ex]
      path[draw=red](0,0)--(textwidth,0);
      endtikzpicture

      enddocument


      enter image description here






      share|improve this answer




















      • 1





        @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

        – marmot
        May 4 at 2:31






      • 1





        @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

        – marmot
        May 4 at 3:31







      • 1





        @bp2017 You should literally never use \ to end a paragraph..

        – L. F.
        May 4 at 5:24







      • 1





        @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

        – marmot
        May 4 at 5:53











      • the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

        – David Carlisle
        May 4 at 8:03













      4












      4








      4







      You shouldn't use \ to end a paragraph and the arguably simplest way is to do everything with TikZ.



      documentclass[border=5mm,varwidth=150mm]standalone
      usepackagetikz
      newcounterbpnode
      tikzsetevery node/.append style=/utils/exec=stepcounterbpnode,
      alias=bpnode-numbervaluebpnode
      begindocument
      begintikzpicture
      node[outer sep=0pt,inner sep=0pt,text width=textwidth,align=left] (txt)
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello;
      path[draw]([yshift=1em]txt.north west)--++(textwidth,0);
      path[draw=red]([yshift=-1em]txt.south west)--++(textwidth,0);
      %draw (bpnode-1) -- ++ (2,0);
      typeoutthetextwidth
      endtikzpicture
      enddocument


      enter image description here



      Here is a "quick and dirty" proposal using the baseline key.



      documentclass[border=5mm,varwidth=150mm]standalone

      usepackagetikz

      begindocument

      begintikzpicture[baseline=-0.6ex]
      path[draw](0,0)--(textwidth,0);
      endtikzpicturepar
      noindent%
      hellopar
      noindent%
      begintikzpicture[baseline=-0.6ex]
      path[draw=red](0,0)--(textwidth,0);
      endtikzpicture

      enddocument


      enter image description here






      share|improve this answer















      You shouldn't use \ to end a paragraph and the arguably simplest way is to do everything with TikZ.



      documentclass[border=5mm,varwidth=150mm]standalone
      usepackagetikz
      newcounterbpnode
      tikzsetevery node/.append style=/utils/exec=stepcounterbpnode,
      alias=bpnode-numbervaluebpnode
      begindocument
      begintikzpicture
      node[outer sep=0pt,inner sep=0pt,text width=textwidth,align=left] (txt)
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello
      hello hello hello hello hello hello hello hello hello;
      path[draw]([yshift=1em]txt.north west)--++(textwidth,0);
      path[draw=red]([yshift=-1em]txt.south west)--++(textwidth,0);
      %draw (bpnode-1) -- ++ (2,0);
      typeoutthetextwidth
      endtikzpicture
      enddocument


      enter image description here



      Here is a "quick and dirty" proposal using the baseline key.



      documentclass[border=5mm,varwidth=150mm]standalone

      usepackagetikz

      begindocument

      begintikzpicture[baseline=-0.6ex]
      path[draw](0,0)--(textwidth,0);
      endtikzpicturepar
      noindent%
      hellopar
      noindent%
      begintikzpicture[baseline=-0.6ex]
      path[draw=red](0,0)--(textwidth,0);
      endtikzpicture

      enddocument


      enter image description here







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 4 at 5:52

























      answered May 4 at 1:55









      marmotmarmot

      127k6162308




      127k6162308







      • 1





        @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

        – marmot
        May 4 at 2:31






      • 1





        @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

        – marmot
        May 4 at 3:31







      • 1





        @bp2017 You should literally never use \ to end a paragraph..

        – L. F.
        May 4 at 5:24







      • 1





        @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

        – marmot
        May 4 at 5:53











      • the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

        – David Carlisle
        May 4 at 8:03












      • 1





        @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

        – marmot
        May 4 at 2:31






      • 1





        @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

        – marmot
        May 4 at 3:31







      • 1





        @bp2017 You should literally never use \ to end a paragraph..

        – L. F.
        May 4 at 5:24







      • 1





        @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

        – marmot
        May 4 at 5:53











      • the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

        – David Carlisle
        May 4 at 8:03







      1




      1





      @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

      – marmot
      May 4 at 2:31





      @bp2017 One should use par to end a paragraph. \ is for tables and the like. If you absolutely do not want to use tikz here, any stable solutions that I can think of will be rather involved. If you want a quick and dirty solution instead, just tune the baseline key of the tikzpictures you use to draw the lines. I'll be happy to spell this out once I am sitting in front of a computer, not just the iPad.

      – marmot
      May 4 at 2:31




      1




      1





      @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

      – marmot
      May 4 at 3:31






      @bp2017 I added a quick and dirty proposal. I do not understand the point about naming. You could just add a counter and use it in order to make the node names unique. This can be automatized, of course.

      – marmot
      May 4 at 3:31





      1




      1





      @bp2017 You should literally never use \ to end a paragraph..

      – L. F.
      May 4 at 5:24






      @bp2017 You should literally never use \ to end a paragraph..

      – L. F.
      May 4 at 5:24





      1




      1





      @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

      – marmot
      May 4 at 5:53





      @bp2017 I don't, that's why it is quick and dirty, and not failsafe. I added a version that automatically numbers the nodes.

      – marmot
      May 4 at 5:53













      the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

      – David Carlisle
      May 4 at 8:03





      the question is not should you use \ to end a paragraph, as \ does not end the paragraph and using it at the end is wrong (and messes up the vertical spacing in the document by adding a spurious white line of text (marked with an underfull hbox warning in the log)

      – David Carlisle
      May 4 at 8:03











      2














      Using TikZ, I would put the text in a node of the desired width, then use the node anchors do draw the lines.



      documentclass[border=5mm,varwidth=150mm]standalone
      usepackagetikz
      begindocument
      begintikzpicture
      node(a)[minimum width=linewidth,text width=linewidth]hello;
      draw(a.north west)--(a.north east);
      draw[red](a.south west)--(a.south east);
      endtikzpicture
      enddocument


      enter image description here



      Here's a non-TikZ answer just to show another approach.



      documentclass[border=5mm,varwidth=150mm]standalone
      usepackagebooktabs
      usepackagecolortbl
      usepackagetabularx
      begindocument
      begintabularxlinewidth@l@
      midrule
      hello\
      arrayrulecolorredmidrule
      endtabularx
      enddocument


      enter image description here






      share|improve this answer



























        2














        Using TikZ, I would put the text in a node of the desired width, then use the node anchors do draw the lines.



        documentclass[border=5mm,varwidth=150mm]standalone
        usepackagetikz
        begindocument
        begintikzpicture
        node(a)[minimum width=linewidth,text width=linewidth]hello;
        draw(a.north west)--(a.north east);
        draw[red](a.south west)--(a.south east);
        endtikzpicture
        enddocument


        enter image description here



        Here's a non-TikZ answer just to show another approach.



        documentclass[border=5mm,varwidth=150mm]standalone
        usepackagebooktabs
        usepackagecolortbl
        usepackagetabularx
        begindocument
        begintabularxlinewidth@l@
        midrule
        hello\
        arrayrulecolorredmidrule
        endtabularx
        enddocument


        enter image description here






        share|improve this answer

























          2












          2








          2







          Using TikZ, I would put the text in a node of the desired width, then use the node anchors do draw the lines.



          documentclass[border=5mm,varwidth=150mm]standalone
          usepackagetikz
          begindocument
          begintikzpicture
          node(a)[minimum width=linewidth,text width=linewidth]hello;
          draw(a.north west)--(a.north east);
          draw[red](a.south west)--(a.south east);
          endtikzpicture
          enddocument


          enter image description here



          Here's a non-TikZ answer just to show another approach.



          documentclass[border=5mm,varwidth=150mm]standalone
          usepackagebooktabs
          usepackagecolortbl
          usepackagetabularx
          begindocument
          begintabularxlinewidth@l@
          midrule
          hello\
          arrayrulecolorredmidrule
          endtabularx
          enddocument


          enter image description here






          share|improve this answer













          Using TikZ, I would put the text in a node of the desired width, then use the node anchors do draw the lines.



          documentclass[border=5mm,varwidth=150mm]standalone
          usepackagetikz
          begindocument
          begintikzpicture
          node(a)[minimum width=linewidth,text width=linewidth]hello;
          draw(a.north west)--(a.north east);
          draw[red](a.south west)--(a.south east);
          endtikzpicture
          enddocument


          enter image description here



          Here's a non-TikZ answer just to show another approach.



          documentclass[border=5mm,varwidth=150mm]standalone
          usepackagebooktabs
          usepackagecolortbl
          usepackagetabularx
          begindocument
          begintabularxlinewidth@l@
          midrule
          hello\
          arrayrulecolorredmidrule
          endtabularx
          enddocument


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 4 at 5:05









          erikerik

          9,21021543




          9,21021543





















              2














              This uses a parbox and vfill. The baselines are ignored in this case, since the baseline of the parbox is more than baselineskip from either above or below, so instead LaTeX adds a gap of lineskip (1pt). Inside the parbox, the vfills expand to the same size. The same effect is achieved by using [c] instead of [s] and vfill, but I wanted to show how it was done.



              documentclass[border=5mm,varwidth=150mm]standalone
              usepackagetikz
              begindocument

              noindentbegintikzpicture
              path[draw](0,0)--(textwidth,0);
              endtikzpicture\
              parbox[c][3baselineskip][s]textwidthvfill
              hello
              vfill\
              begintikzpicture
              path[draw=red](0,0)--(textwidth,0);
              endtikzpicture

              enddocument



              This uses raisebox to move the text relative to the baseline. The rule shows where the baseline is located.



              documentclass[border=5mm,varwidth=150mm]standalone
              usepackagetikz
              begindocument

              begintikzpicture
              path[draw](0,0)--(textwidth,0);
              endtikzpicture\
              raiseboxdimexpr 0.5depth-0.5heightHellow
              rule1em0.5pt
              raiseboxdimexpr 0.5depth-0.5heightpygmy\
              begintikzpicture
              path[draw=red](0,0)--(textwidth,0);
              endtikzpicture

              enddocument


              demo






              share|improve this answer





























                2














                This uses a parbox and vfill. The baselines are ignored in this case, since the baseline of the parbox is more than baselineskip from either above or below, so instead LaTeX adds a gap of lineskip (1pt). Inside the parbox, the vfills expand to the same size. The same effect is achieved by using [c] instead of [s] and vfill, but I wanted to show how it was done.



                documentclass[border=5mm,varwidth=150mm]standalone
                usepackagetikz
                begindocument

                noindentbegintikzpicture
                path[draw](0,0)--(textwidth,0);
                endtikzpicture\
                parbox[c][3baselineskip][s]textwidthvfill
                hello
                vfill\
                begintikzpicture
                path[draw=red](0,0)--(textwidth,0);
                endtikzpicture

                enddocument



                This uses raisebox to move the text relative to the baseline. The rule shows where the baseline is located.



                documentclass[border=5mm,varwidth=150mm]standalone
                usepackagetikz
                begindocument

                begintikzpicture
                path[draw](0,0)--(textwidth,0);
                endtikzpicture\
                raiseboxdimexpr 0.5depth-0.5heightHellow
                rule1em0.5pt
                raiseboxdimexpr 0.5depth-0.5heightpygmy\
                begintikzpicture
                path[draw=red](0,0)--(textwidth,0);
                endtikzpicture

                enddocument


                demo






                share|improve this answer



























                  2












                  2








                  2







                  This uses a parbox and vfill. The baselines are ignored in this case, since the baseline of the parbox is more than baselineskip from either above or below, so instead LaTeX adds a gap of lineskip (1pt). Inside the parbox, the vfills expand to the same size. The same effect is achieved by using [c] instead of [s] and vfill, but I wanted to show how it was done.



                  documentclass[border=5mm,varwidth=150mm]standalone
                  usepackagetikz
                  begindocument

                  noindentbegintikzpicture
                  path[draw](0,0)--(textwidth,0);
                  endtikzpicture\
                  parbox[c][3baselineskip][s]textwidthvfill
                  hello
                  vfill\
                  begintikzpicture
                  path[draw=red](0,0)--(textwidth,0);
                  endtikzpicture

                  enddocument



                  This uses raisebox to move the text relative to the baseline. The rule shows where the baseline is located.



                  documentclass[border=5mm,varwidth=150mm]standalone
                  usepackagetikz
                  begindocument

                  begintikzpicture
                  path[draw](0,0)--(textwidth,0);
                  endtikzpicture\
                  raiseboxdimexpr 0.5depth-0.5heightHellow
                  rule1em0.5pt
                  raiseboxdimexpr 0.5depth-0.5heightpygmy\
                  begintikzpicture
                  path[draw=red](0,0)--(textwidth,0);
                  endtikzpicture

                  enddocument


                  demo






                  share|improve this answer















                  This uses a parbox and vfill. The baselines are ignored in this case, since the baseline of the parbox is more than baselineskip from either above or below, so instead LaTeX adds a gap of lineskip (1pt). Inside the parbox, the vfills expand to the same size. The same effect is achieved by using [c] instead of [s] and vfill, but I wanted to show how it was done.



                  documentclass[border=5mm,varwidth=150mm]standalone
                  usepackagetikz
                  begindocument

                  noindentbegintikzpicture
                  path[draw](0,0)--(textwidth,0);
                  endtikzpicture\
                  parbox[c][3baselineskip][s]textwidthvfill
                  hello
                  vfill\
                  begintikzpicture
                  path[draw=red](0,0)--(textwidth,0);
                  endtikzpicture

                  enddocument



                  This uses raisebox to move the text relative to the baseline. The rule shows where the baseline is located.



                  documentclass[border=5mm,varwidth=150mm]standalone
                  usepackagetikz
                  begindocument

                  begintikzpicture
                  path[draw](0,0)--(textwidth,0);
                  endtikzpicture\
                  raiseboxdimexpr 0.5depth-0.5heightHellow
                  rule1em0.5pt
                  raiseboxdimexpr 0.5depth-0.5heightpygmy\
                  begintikzpicture
                  path[draw=red](0,0)--(textwidth,0);
                  endtikzpicture

                  enddocument


                  demo







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 days ago

























                  answered May 4 at 3:41









                  John KormyloJohn Kormylo

                  47.6k32674




                  47.6k32674





















                      1














                      Why use TikZ at all?



                      documentclassarticle

                      usepackagexcolor

                      begindocument

                      hrule
                      vspace1ex
                      noindent
                      hello
                      vspace1ex
                      colorredhrule

                      enddocument`


                      MWE output



                      As mentioned by others, if you really want to use TikZ you should put the text in a node.




                      If you want to use this a lot in your document you should of course make it a macro:



                      documentclassarticle

                      usepackagexparse
                      usepackagetikz

                      NewDocumentCommandmymacroO.5baselineskip O.25baselineskip +m o Ored%
                      vspace#2%
                      IfValueT#4color#4hrule%
                      vspace#1%
                      noindent #3%
                      vspace#1%
                      color#5hrule%
                      vspace#2%


                      NewDocumentCommandmytikzmacroO.5baselineskip O.25baselineskip +m O O%
                      parnoindent
                      begintikzpicture [line cap=butt]
                      node [outer sep=0pt, inner sep=0pt, inner ysep=#1, text width=textwidth-.4pt] (txt) #3;
                      draw [#4] (txt.north west) -- (txt.north east);
                      draw [red, #5] (txt.south west) -- (txt.south east);
                      clip ([yshift=-#2] current bounding box.south west) rectangle ([yshift=#2] current bounding box.north east);
                      endtikzpicture%


                      begindocument

                      mymacroHello World!

                      mytikzmacroAdieu World!

                      enddocument


                      macro MWE output




                      If what you are trying to do is just putting some frames around text, you might also want to have a look at packages designed for that purpose, like mdframed or tcolorbox.






                      share|improve this answer

























                      • I've been told hrule breaks spacing in a bad way (better use something else?).

                        – bp2017
                        May 4 at 15:27












                      • By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

                        – bp2017
                        May 4 at 15:43











                      • One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

                        – schtandard
                        May 5 at 0:00











                      • You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

                        – schtandard
                        May 5 at 0:01















                      1














                      Why use TikZ at all?



                      documentclassarticle

                      usepackagexcolor

                      begindocument

                      hrule
                      vspace1ex
                      noindent
                      hello
                      vspace1ex
                      colorredhrule

                      enddocument`


                      MWE output



                      As mentioned by others, if you really want to use TikZ you should put the text in a node.




                      If you want to use this a lot in your document you should of course make it a macro:



                      documentclassarticle

                      usepackagexparse
                      usepackagetikz

                      NewDocumentCommandmymacroO.5baselineskip O.25baselineskip +m o Ored%
                      vspace#2%
                      IfValueT#4color#4hrule%
                      vspace#1%
                      noindent #3%
                      vspace#1%
                      color#5hrule%
                      vspace#2%


                      NewDocumentCommandmytikzmacroO.5baselineskip O.25baselineskip +m O O%
                      parnoindent
                      begintikzpicture [line cap=butt]
                      node [outer sep=0pt, inner sep=0pt, inner ysep=#1, text width=textwidth-.4pt] (txt) #3;
                      draw [#4] (txt.north west) -- (txt.north east);
                      draw [red, #5] (txt.south west) -- (txt.south east);
                      clip ([yshift=-#2] current bounding box.south west) rectangle ([yshift=#2] current bounding box.north east);
                      endtikzpicture%


                      begindocument

                      mymacroHello World!

                      mytikzmacroAdieu World!

                      enddocument


                      macro MWE output




                      If what you are trying to do is just putting some frames around text, you might also want to have a look at packages designed for that purpose, like mdframed or tcolorbox.






                      share|improve this answer

























                      • I've been told hrule breaks spacing in a bad way (better use something else?).

                        – bp2017
                        May 4 at 15:27












                      • By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

                        – bp2017
                        May 4 at 15:43











                      • One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

                        – schtandard
                        May 5 at 0:00











                      • You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

                        – schtandard
                        May 5 at 0:01













                      1












                      1








                      1







                      Why use TikZ at all?



                      documentclassarticle

                      usepackagexcolor

                      begindocument

                      hrule
                      vspace1ex
                      noindent
                      hello
                      vspace1ex
                      colorredhrule

                      enddocument`


                      MWE output



                      As mentioned by others, if you really want to use TikZ you should put the text in a node.




                      If you want to use this a lot in your document you should of course make it a macro:



                      documentclassarticle

                      usepackagexparse
                      usepackagetikz

                      NewDocumentCommandmymacroO.5baselineskip O.25baselineskip +m o Ored%
                      vspace#2%
                      IfValueT#4color#4hrule%
                      vspace#1%
                      noindent #3%
                      vspace#1%
                      color#5hrule%
                      vspace#2%


                      NewDocumentCommandmytikzmacroO.5baselineskip O.25baselineskip +m O O%
                      parnoindent
                      begintikzpicture [line cap=butt]
                      node [outer sep=0pt, inner sep=0pt, inner ysep=#1, text width=textwidth-.4pt] (txt) #3;
                      draw [#4] (txt.north west) -- (txt.north east);
                      draw [red, #5] (txt.south west) -- (txt.south east);
                      clip ([yshift=-#2] current bounding box.south west) rectangle ([yshift=#2] current bounding box.north east);
                      endtikzpicture%


                      begindocument

                      mymacroHello World!

                      mytikzmacroAdieu World!

                      enddocument


                      macro MWE output




                      If what you are trying to do is just putting some frames around text, you might also want to have a look at packages designed for that purpose, like mdframed or tcolorbox.






                      share|improve this answer















                      Why use TikZ at all?



                      documentclassarticle

                      usepackagexcolor

                      begindocument

                      hrule
                      vspace1ex
                      noindent
                      hello
                      vspace1ex
                      colorredhrule

                      enddocument`


                      MWE output



                      As mentioned by others, if you really want to use TikZ you should put the text in a node.




                      If you want to use this a lot in your document you should of course make it a macro:



                      documentclassarticle

                      usepackagexparse
                      usepackagetikz

                      NewDocumentCommandmymacroO.5baselineskip O.25baselineskip +m o Ored%
                      vspace#2%
                      IfValueT#4color#4hrule%
                      vspace#1%
                      noindent #3%
                      vspace#1%
                      color#5hrule%
                      vspace#2%


                      NewDocumentCommandmytikzmacroO.5baselineskip O.25baselineskip +m O O%
                      parnoindent
                      begintikzpicture [line cap=butt]
                      node [outer sep=0pt, inner sep=0pt, inner ysep=#1, text width=textwidth-.4pt] (txt) #3;
                      draw [#4] (txt.north west) -- (txt.north east);
                      draw [red, #5] (txt.south west) -- (txt.south east);
                      clip ([yshift=-#2] current bounding box.south west) rectangle ([yshift=#2] current bounding box.north east);
                      endtikzpicture%


                      begindocument

                      mymacroHello World!

                      mytikzmacroAdieu World!

                      enddocument


                      macro MWE output




                      If what you are trying to do is just putting some frames around text, you might also want to have a look at packages designed for that purpose, like mdframed or tcolorbox.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 4 at 11:33

























                      answered May 4 at 11:01









                      schtandardschtandard

                      2,5921121




                      2,5921121












                      • I've been told hrule breaks spacing in a bad way (better use something else?).

                        – bp2017
                        May 4 at 15:27












                      • By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

                        – bp2017
                        May 4 at 15:43











                      • One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

                        – schtandard
                        May 5 at 0:00











                      • You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

                        – schtandard
                        May 5 at 0:01

















                      • I've been told hrule breaks spacing in a bad way (better use something else?).

                        – bp2017
                        May 4 at 15:27












                      • By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

                        – bp2017
                        May 4 at 15:43











                      • One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

                        – schtandard
                        May 5 at 0:00











                      • You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

                        – schtandard
                        May 5 at 0:01
















                      I've been told hrule breaks spacing in a bad way (better use something else?).

                      – bp2017
                      May 4 at 15:27






                      I've been told hrule breaks spacing in a bad way (better use something else?).

                      – bp2017
                      May 4 at 15:27














                      By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

                      – bp2017
                      May 4 at 15:43





                      By the way, how do you remove (in your example) vspace between bottom red line of "Hello World!" and top black line of "Adieu World!"?

                      – bp2017
                      May 4 at 15:43













                      One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

                      – schtandard
                      May 5 at 0:00





                      One has to be a bit careful with hrule, yes. Depending on the contexts in which you want to use this, you may be better off using a macro that's a bit tamer. (Actually, one has to think about these things with other approaches as well (though hrule is "extra special"). Depending on the environments in which this is to be used, the TikZ solution or one of the packages mentioned may be better. The advantage of hrule is that it removes interline space, which would have to be taken care of additionally with rule.

                      – schtandard
                      May 5 at 0:00













                      You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

                      – schtandard
                      May 5 at 0:01





                      You can remove the space above the black and below the red line by setting the second argument of the macros to 0pt. If you never want any space there, you can remove it (and the corresponding lines in the macro definition) entirely.

                      – schtandard
                      May 5 at 0:01











                      0














                      Check this out.



                      documentclass[border=5mm,varwidth=150mm]standalone

                      usepackagetikz

                      begindocument

                      begintikzpicture
                      path[draw](0,0)--(textwidth,0);
                      endtikzpicture

                      nointerlineskipvspace5pt
                      hello xy % or use par to replace following blank line

                      nointerlineskipvspace5pt
                      begintikzpicture
                      path[draw=red](0,0)--(textwidth,0);
                      endtikzpicture

                      enddocument







                      share|improve this answer


















                      • 1





                        in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

                        – David Carlisle
                        May 4 at 8:05











                      • @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

                        – bp2017
                        May 4 at 15:25












                      • @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

                        – bp2017
                        May 4 at 15:46












                      • you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

                        – David Carlisle
                        May 4 at 16:35











                      • @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

                        – bp2017
                        May 5 at 1:15
















                      0














                      Check this out.



                      documentclass[border=5mm,varwidth=150mm]standalone

                      usepackagetikz

                      begindocument

                      begintikzpicture
                      path[draw](0,0)--(textwidth,0);
                      endtikzpicture

                      nointerlineskipvspace5pt
                      hello xy % or use par to replace following blank line

                      nointerlineskipvspace5pt
                      begintikzpicture
                      path[draw=red](0,0)--(textwidth,0);
                      endtikzpicture

                      enddocument







                      share|improve this answer


















                      • 1





                        in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

                        – David Carlisle
                        May 4 at 8:05











                      • @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

                        – bp2017
                        May 4 at 15:25












                      • @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

                        – bp2017
                        May 4 at 15:46












                      • you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

                        – David Carlisle
                        May 4 at 16:35











                      • @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

                        – bp2017
                        May 5 at 1:15














                      0












                      0








                      0







                      Check this out.



                      documentclass[border=5mm,varwidth=150mm]standalone

                      usepackagetikz

                      begindocument

                      begintikzpicture
                      path[draw](0,0)--(textwidth,0);
                      endtikzpicture

                      nointerlineskipvspace5pt
                      hello xy % or use par to replace following blank line

                      nointerlineskipvspace5pt
                      begintikzpicture
                      path[draw=red](0,0)--(textwidth,0);
                      endtikzpicture

                      enddocument







                      share|improve this answer













                      Check this out.



                      documentclass[border=5mm,varwidth=150mm]standalone

                      usepackagetikz

                      begindocument

                      begintikzpicture
                      path[draw](0,0)--(textwidth,0);
                      endtikzpicture

                      nointerlineskipvspace5pt
                      hello xy % or use par to replace following blank line

                      nointerlineskipvspace5pt
                      begintikzpicture
                      path[draw=red](0,0)--(textwidth,0);
                      endtikzpicture

                      enddocument








                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 4 at 6:05









                      bp2017bp2017

                      915116




                      915116







                      • 1





                        in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

                        – David Carlisle
                        May 4 at 8:05











                      • @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

                        – bp2017
                        May 4 at 15:25












                      • @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

                        – bp2017
                        May 4 at 15:46












                      • you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

                        – David Carlisle
                        May 4 at 16:35











                      • @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

                        – bp2017
                        May 5 at 1:15













                      • 1





                        in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

                        – David Carlisle
                        May 4 at 8:05











                      • @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

                        – bp2017
                        May 4 at 15:25












                      • @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

                        – bp2017
                        May 4 at 15:46












                      • you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

                        – David Carlisle
                        May 4 at 16:35











                      • @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

                        – bp2017
                        May 5 at 1:15








                      1




                      1





                      in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

                      – David Carlisle
                      May 4 at 8:05





                      in almost all documents you need even line spacing, nointerlineskip here will break that, meaning that the descender on the y affects the position of following items, is that really what you want?

                      – David Carlisle
                      May 4 at 8:05













                      @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

                      – bp2017
                      May 4 at 15:25






                      @DavidCarlisle, of course not. I had no idea. What I want is to place block of text (or math) between the lines so that vspace which immediately follows top line and immediately precedes bottom line is the same (and can be adjusted to any value). I've been suggested to use nointerlineskip in one of my other questions (on getting rid of extra vertical space after center environment).

                      – bp2017
                      May 4 at 15:25














                      @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

                      – bp2017
                      May 4 at 15:46






                      @DavidCarlisle, does use of hrule in @schtandard's answer have similar effect to nointerlineskip (considering hrule was deemed inappropriate when dealing with vspace of math-mode)? And what are complications of descender on y affecting position of following items? And what is a safe alternative to nointerlineskip?

                      – bp2017
                      May 4 at 15:46














                      you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

                      – David Carlisle
                      May 4 at 16:35





                      you didn't answer what you want to happen, or what you mean by evenly spaced. you have a rule above and a rule below hello do you want the same space from the rule to the top of the h and from the bottom of the h to the rule, if so if you add xy do you want the bottom rule to move down so the space from the bottom of the y to the rule matches (that seems to be what you do here, but is unusual requirement) similarly if you change the text to Hello do you want it all to move down so the gap is measured from the rule to the top of the H, again that would be an unusual requirement.

                      – David Carlisle
                      May 4 at 16:35













                      @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

                      – bp2017
                      May 5 at 1:15






                      @DavidCarlisle, here (tex.stackexchange.com/q/489237/141768) I ask a new question where (this time) I describe in detail everything I need.

                      – bp2017
                      May 5 at 1:15


















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489074%2fhow-in-the-world-do-i-place-line-of-text-evenly-between-two-horizontal-tikz-line%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

                      How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

                      What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

                      Why did Thanos need his ship to help him in the battle scene?Which actor plays Thanos in the Avengers mid-credits scene?Are there economic implications portrayed in comics where the buildings and cities are ruined almost daily?Old X-Men comic where team travels to alien world with a ring-like sun that needs recharging?Why does Ego need help sleeping?Is there an objective answer to who “the strongest Avenger” is?How did Banner get unstuck?Why did Thanos get hit?How did Thanos (or anyone) know the Infinity Stones would give him this power?Did Thanos leave Eitri alive for his after-sales service?In Avengers 1, why does Thanos need Loki?