Spacing after a tikz figureSymbol for external linksTikZ: Cropping the Bounding Boxhow to set the canvas and font size in TikZ?How to define the default vertical distance between nodes?How to fill a line one-sided using TikZ?Line up nested tikz enviroments or how to get rid of themTikZ: Place different elements of a same path on various layerstikz - gradient along a bendy pathSpacing after figure without captionThe TikZ pipeline: A path's 'draw' option has no effect on a 'behind path' nodeTikZ and FIFA WorldCup 2018: Flags of Nations

Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?

Is it error of law to judge on less relevant case law when there is much more relevant one?

Copying an existing HTML page and use it, is that against any copyright law?

Anti-cheating: should there be a limit to a number of toilet breaks per game per player?

Desktop app status bar: Notification vs error message

Does Dispel Magic destroy Artificer Turrets?

Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?

How did the Axis intend to hold the Caucasus?

Is it safe if the neutral lead is exposed and disconnected?

What steps would an amateur scientist have to take in order to get a scientific breakthrough published?

How could Nomadic scholars effectively memorize libraries worth of information

How long until two planets become one?

What did G-d do before Creation?

Compound Word Neologism

Why isn't there any 9.5 digit multimeter or higher?

Why does Canada require mandatory bilingualism in a lot of federal government posts?

How do I use JSON.generator to generate an unnamed array?

Is there an antonym(a complementary antonym) for "spicy" or "hot" regarding food (I do NOT mean "seasoned" but "hot")?

Exploiting the delay when a festival ticket is scanned

How can Paypal know my card is being used in another account?

How many oliphaunts died in all of the Lord of the Rings battles?

What is more environmentally friendly? An A320 or a car?

If Trump gets impeached, how long would Pence be president?

What are the closest international airports in different countries?



Spacing after a tikz figure


Symbol for external linksTikZ: Cropping the Bounding Boxhow to set the canvas and font size in TikZ?How to define the default vertical distance between nodes?How to fill a line one-sided using TikZ?Line up nested tikz enviroments or how to get rid of themTikZ: Place different elements of a same path on various layerstikz - gradient along a bendy pathSpacing after figure without captionThe TikZ pipeline: A path's 'draw' option has no effect on a 'behind path' nodeTikZ and FIFA WorldCup 2018: Flags of Nations






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?



documentclassarticle
usepackagetikz,hyperref
newcommandExternalLink%
tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);



letorighrefhref
renewcommandhref[2]orighref#1#2$,$ExternalLink

begindocument
noindent
Some text hrefhttp://google.comlink some more text.\
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
enddocument


enter image description here










share|improve this question






























    2















    I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?



    documentclassarticle
    usepackagetikz,hyperref
    newcommandExternalLink%
    tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
    beginscope[x=1ex, y=1ex]
    clip (-0.1,-0.1)
    --++ (-0, 1.2)
    --++ (0.6, 0)
    --++ (0, -0.6)
    --++ (0.6, 0)
    --++ (0, -1);
    path[draw=black, line width = 0.5,
    rounded corners=0.5] (0,0) rectangle (1,1);
    endscope
    path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
    path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);



    letorighrefhref
    renewcommandhref[2]orighref#1#2$,$ExternalLink

    begindocument
    noindent
    Some text hrefhttp://google.comlink some more text.\
    Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
    enddocument


    enter image description here










    share|improve this question


























      2












      2








      2








      I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?



      documentclassarticle
      usepackagetikz,hyperref
      newcommandExternalLink%
      tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
      beginscope[x=1ex, y=1ex]
      clip (-0.1,-0.1)
      --++ (-0, 1.2)
      --++ (0.6, 0)
      --++ (0, -0.6)
      --++ (0.6, 0)
      --++ (0, -1);
      path[draw=black, line width = 0.5,
      rounded corners=0.5] (0,0) rectangle (1,1);
      endscope
      path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
      path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);



      letorighrefhref
      renewcommandhref[2]orighref#1#2$,$ExternalLink

      begindocument
      noindent
      Some text hrefhttp://google.comlink some more text.\
      Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
      enddocument


      enter image description here










      share|improve this question














      I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?



      documentclassarticle
      usepackagetikz,hyperref
      newcommandExternalLink%
      tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
      beginscope[x=1ex, y=1ex]
      clip (-0.1,-0.1)
      --++ (-0, 1.2)
      --++ (0.6, 0)
      --++ (0, -0.6)
      --++ (0.6, 0)
      --++ (0, -1);
      path[draw=black, line width = 0.5,
      rounded corners=0.5] (0,0) rectangle (1,1);
      endscope
      path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
      path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);



      letorighrefhref
      renewcommandhref[2]orighref#1#2$,$ExternalLink

      begindocument
      noindent
      Some text hrefhttp://google.comlink some more text.\
      Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
      enddocument


      enter image description here







      tikz-pgf spacing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      Nicolas RougierNicolas Rougier

      1505 bronze badges




      1505 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          5














          When you write:



          Some text orighrefhttp://google.comlink$,$ExternalLink some more text.


          the space after ExternalLink is ignored by TeX, because ExternalLink is a control sequence whose name ends with a letter. On the contrary, with:



          Some text hrefhttp://google.comlink some more text.


          there is a space token after link, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:



          Some text hrefhttp://google.comlinksome more text.


          or use ignorespaces in your redefinition of href so as to ignore spaces following in the input (ignorespaces expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):



          renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces


          But actually, you don't want to use any of these suggestions. This is because in your ExternalLink command, there is a most probably unwanted space:



          newcommandExternalLink%

          ...

          path[draw=black, ...] ... ;
          % <------- here, remove the space
          }


          So, your ExternalLink command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces anymore.



          Also note that you don't need to be in math mode in order to use ,; it produces a thinspace when used outside of math mode. So, you can do something like:



          renewcommand*href[2]orighref#1#2,ExternalLink


          Other suggestion: you may want to include the icon inside the clickable link:



          renewcommand*href[2]orighref#1#2,ExternalLink


          I used renewcommand* because the arguments of href most probably shouldn't contain par tokens; this makes finding errors easier.



          Note: there won't be a line break at the ,, because this macro expands to thinspace in non-math mode, which itself expands to a kern, and there can be a break at a kern only if it's immediately followed by glue—which isn't the case here, as ExternalLink starts with a box: the TikZ picture.



          Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href (i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox command doesn't need to be protected, as the example shows):



          documentclassarticle
          usepackagetikz
          usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links

          newsaveboxExternalLinkIcon

          beginlrboxExternalLinkIcon
          begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
          beginscope[x=1ex, y=1ex]
          clip (-0.1,-0.1)
          --++ (-0, 1.2)
          --++ (0.6, 0)
          --++ (0, -0.6)
          --++ (0.6, 0)
          --++ (0, -1);
          path[draw=black, line width = 0.5,
          rounded corners=0.5] (0,0) rectangle (1,1);
          endscope
          path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
          path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
          endtikzpicture% <--- important!
          endlrbox

          letorighrefhref

          renewcommand*href[2]%
          orighref#1#2,useboxExternalLinkIcon%


          begindocument

          noindent
          Some text hrefhttp://example.comlink some more text. Spacing is also fine
          before a hrefhttp://example.comcomma, as you can see. Periods are fine
          too, of course---we don't have to do anything special.

          beginfigure[htbp]
          centering
          This is the figure contents.
          captionA caption containing a hrefhttp://example.comhyperlink
          endfigure

          enddocument


          Screenshot






          share|improve this answer



























          • Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

            – Nicolas Rougier
            7 hours ago






          • 1





            This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

            – frougon
            7 hours ago











          • There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

            – frougon
            5 hours ago













          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%2f501981%2fspacing-after-a-tikz-figure%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          When you write:



          Some text orighrefhttp://google.comlink$,$ExternalLink some more text.


          the space after ExternalLink is ignored by TeX, because ExternalLink is a control sequence whose name ends with a letter. On the contrary, with:



          Some text hrefhttp://google.comlink some more text.


          there is a space token after link, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:



          Some text hrefhttp://google.comlinksome more text.


          or use ignorespaces in your redefinition of href so as to ignore spaces following in the input (ignorespaces expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):



          renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces


          But actually, you don't want to use any of these suggestions. This is because in your ExternalLink command, there is a most probably unwanted space:



          newcommandExternalLink%

          ...

          path[draw=black, ...] ... ;
          % <------- here, remove the space
          }


          So, your ExternalLink command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces anymore.



          Also note that you don't need to be in math mode in order to use ,; it produces a thinspace when used outside of math mode. So, you can do something like:



          renewcommand*href[2]orighref#1#2,ExternalLink


          Other suggestion: you may want to include the icon inside the clickable link:



          renewcommand*href[2]orighref#1#2,ExternalLink


          I used renewcommand* because the arguments of href most probably shouldn't contain par tokens; this makes finding errors easier.



          Note: there won't be a line break at the ,, because this macro expands to thinspace in non-math mode, which itself expands to a kern, and there can be a break at a kern only if it's immediately followed by glue—which isn't the case here, as ExternalLink starts with a box: the TikZ picture.



          Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href (i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox command doesn't need to be protected, as the example shows):



          documentclassarticle
          usepackagetikz
          usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links

          newsaveboxExternalLinkIcon

          beginlrboxExternalLinkIcon
          begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
          beginscope[x=1ex, y=1ex]
          clip (-0.1,-0.1)
          --++ (-0, 1.2)
          --++ (0.6, 0)
          --++ (0, -0.6)
          --++ (0.6, 0)
          --++ (0, -1);
          path[draw=black, line width = 0.5,
          rounded corners=0.5] (0,0) rectangle (1,1);
          endscope
          path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
          path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
          endtikzpicture% <--- important!
          endlrbox

          letorighrefhref

          renewcommand*href[2]%
          orighref#1#2,useboxExternalLinkIcon%


          begindocument

          noindent
          Some text hrefhttp://example.comlink some more text. Spacing is also fine
          before a hrefhttp://example.comcomma, as you can see. Periods are fine
          too, of course---we don't have to do anything special.

          beginfigure[htbp]
          centering
          This is the figure contents.
          captionA caption containing a hrefhttp://example.comhyperlink
          endfigure

          enddocument


          Screenshot






          share|improve this answer



























          • Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

            – Nicolas Rougier
            7 hours ago






          • 1





            This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

            – frougon
            7 hours ago











          • There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

            – frougon
            5 hours ago















          5














          When you write:



          Some text orighrefhttp://google.comlink$,$ExternalLink some more text.


          the space after ExternalLink is ignored by TeX, because ExternalLink is a control sequence whose name ends with a letter. On the contrary, with:



          Some text hrefhttp://google.comlink some more text.


          there is a space token after link, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:



          Some text hrefhttp://google.comlinksome more text.


          or use ignorespaces in your redefinition of href so as to ignore spaces following in the input (ignorespaces expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):



          renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces


          But actually, you don't want to use any of these suggestions. This is because in your ExternalLink command, there is a most probably unwanted space:



          newcommandExternalLink%

          ...

          path[draw=black, ...] ... ;
          % <------- here, remove the space
          }


          So, your ExternalLink command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces anymore.



          Also note that you don't need to be in math mode in order to use ,; it produces a thinspace when used outside of math mode. So, you can do something like:



          renewcommand*href[2]orighref#1#2,ExternalLink


          Other suggestion: you may want to include the icon inside the clickable link:



          renewcommand*href[2]orighref#1#2,ExternalLink


          I used renewcommand* because the arguments of href most probably shouldn't contain par tokens; this makes finding errors easier.



          Note: there won't be a line break at the ,, because this macro expands to thinspace in non-math mode, which itself expands to a kern, and there can be a break at a kern only if it's immediately followed by glue—which isn't the case here, as ExternalLink starts with a box: the TikZ picture.



          Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href (i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox command doesn't need to be protected, as the example shows):



          documentclassarticle
          usepackagetikz
          usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links

          newsaveboxExternalLinkIcon

          beginlrboxExternalLinkIcon
          begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
          beginscope[x=1ex, y=1ex]
          clip (-0.1,-0.1)
          --++ (-0, 1.2)
          --++ (0.6, 0)
          --++ (0, -0.6)
          --++ (0.6, 0)
          --++ (0, -1);
          path[draw=black, line width = 0.5,
          rounded corners=0.5] (0,0) rectangle (1,1);
          endscope
          path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
          path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
          endtikzpicture% <--- important!
          endlrbox

          letorighrefhref

          renewcommand*href[2]%
          orighref#1#2,useboxExternalLinkIcon%


          begindocument

          noindent
          Some text hrefhttp://example.comlink some more text. Spacing is also fine
          before a hrefhttp://example.comcomma, as you can see. Periods are fine
          too, of course---we don't have to do anything special.

          beginfigure[htbp]
          centering
          This is the figure contents.
          captionA caption containing a hrefhttp://example.comhyperlink
          endfigure

          enddocument


          Screenshot






          share|improve this answer



























          • Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

            – Nicolas Rougier
            7 hours ago






          • 1





            This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

            – frougon
            7 hours ago











          • There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

            – frougon
            5 hours ago













          5












          5








          5







          When you write:



          Some text orighrefhttp://google.comlink$,$ExternalLink some more text.


          the space after ExternalLink is ignored by TeX, because ExternalLink is a control sequence whose name ends with a letter. On the contrary, with:



          Some text hrefhttp://google.comlink some more text.


          there is a space token after link, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:



          Some text hrefhttp://google.comlinksome more text.


          or use ignorespaces in your redefinition of href so as to ignore spaces following in the input (ignorespaces expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):



          renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces


          But actually, you don't want to use any of these suggestions. This is because in your ExternalLink command, there is a most probably unwanted space:



          newcommandExternalLink%

          ...

          path[draw=black, ...] ... ;
          % <------- here, remove the space
          }


          So, your ExternalLink command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces anymore.



          Also note that you don't need to be in math mode in order to use ,; it produces a thinspace when used outside of math mode. So, you can do something like:



          renewcommand*href[2]orighref#1#2,ExternalLink


          Other suggestion: you may want to include the icon inside the clickable link:



          renewcommand*href[2]orighref#1#2,ExternalLink


          I used renewcommand* because the arguments of href most probably shouldn't contain par tokens; this makes finding errors easier.



          Note: there won't be a line break at the ,, because this macro expands to thinspace in non-math mode, which itself expands to a kern, and there can be a break at a kern only if it's immediately followed by glue—which isn't the case here, as ExternalLink starts with a box: the TikZ picture.



          Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href (i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox command doesn't need to be protected, as the example shows):



          documentclassarticle
          usepackagetikz
          usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links

          newsaveboxExternalLinkIcon

          beginlrboxExternalLinkIcon
          begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
          beginscope[x=1ex, y=1ex]
          clip (-0.1,-0.1)
          --++ (-0, 1.2)
          --++ (0.6, 0)
          --++ (0, -0.6)
          --++ (0.6, 0)
          --++ (0, -1);
          path[draw=black, line width = 0.5,
          rounded corners=0.5] (0,0) rectangle (1,1);
          endscope
          path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
          path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
          endtikzpicture% <--- important!
          endlrbox

          letorighrefhref

          renewcommand*href[2]%
          orighref#1#2,useboxExternalLinkIcon%


          begindocument

          noindent
          Some text hrefhttp://example.comlink some more text. Spacing is also fine
          before a hrefhttp://example.comcomma, as you can see. Periods are fine
          too, of course---we don't have to do anything special.

          beginfigure[htbp]
          centering
          This is the figure contents.
          captionA caption containing a hrefhttp://example.comhyperlink
          endfigure

          enddocument


          Screenshot






          share|improve this answer















          When you write:



          Some text orighrefhttp://google.comlink$,$ExternalLink some more text.


          the space after ExternalLink is ignored by TeX, because ExternalLink is a control sequence whose name ends with a letter. On the contrary, with:



          Some text hrefhttp://google.comlink some more text.


          there is a space token after link, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:



          Some text hrefhttp://google.comlinksome more text.


          or use ignorespaces in your redefinition of href so as to ignore spaces following in the input (ignorespaces expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):



          renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces


          But actually, you don't want to use any of these suggestions. This is because in your ExternalLink command, there is a most probably unwanted space:



          newcommandExternalLink%

          ...

          path[draw=black, ...] ... ;
          % <------- here, remove the space
          }


          So, your ExternalLink command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces anymore.



          Also note that you don't need to be in math mode in order to use ,; it produces a thinspace when used outside of math mode. So, you can do something like:



          renewcommand*href[2]orighref#1#2,ExternalLink


          Other suggestion: you may want to include the icon inside the clickable link:



          renewcommand*href[2]orighref#1#2,ExternalLink


          I used renewcommand* because the arguments of href most probably shouldn't contain par tokens; this makes finding errors easier.



          Note: there won't be a line break at the ,, because this macro expands to thinspace in non-math mode, which itself expands to a kern, and there can be a break at a kern only if it's immediately followed by glue—which isn't the case here, as ExternalLink starts with a box: the TikZ picture.



          Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href (i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox command doesn't need to be protected, as the example shows):



          documentclassarticle
          usepackagetikz
          usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links

          newsaveboxExternalLinkIcon

          beginlrboxExternalLinkIcon
          begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
          beginscope[x=1ex, y=1ex]
          clip (-0.1,-0.1)
          --++ (-0, 1.2)
          --++ (0.6, 0)
          --++ (0, -0.6)
          --++ (0.6, 0)
          --++ (0, -1);
          path[draw=black, line width = 0.5,
          rounded corners=0.5] (0,0) rectangle (1,1);
          endscope
          path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
          path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
          endtikzpicture% <--- important!
          endlrbox

          letorighrefhref

          renewcommand*href[2]%
          orighref#1#2,useboxExternalLinkIcon%


          begindocument

          noindent
          Some text hrefhttp://example.comlink some more text. Spacing is also fine
          before a hrefhttp://example.comcomma, as you can see. Periods are fine
          too, of course---we don't have to do anything special.

          beginfigure[htbp]
          centering
          This is the figure contents.
          captionA caption containing a hrefhttp://example.comhyperlink
          endfigure

          enddocument


          Screenshot







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 9 hours ago









          frougonfrougon

          6,0251 gold badge10 silver badges20 bronze badges




          6,0251 gold badge10 silver badges20 bronze badges















          • Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

            – Nicolas Rougier
            7 hours ago






          • 1





            This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

            – frougon
            7 hours ago











          • There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

            – frougon
            5 hours ago

















          • Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

            – Nicolas Rougier
            7 hours ago






          • 1





            This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

            – frougon
            7 hours ago











          • There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

            – frougon
            5 hours ago
















          Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

          – Nicolas Rougier
          7 hours ago





          Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...

          – Nicolas Rougier
          7 hours ago




          1




          1





          This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

          – frougon
          7 hours ago





          This is probably due to the fact that a caption is subject to protected@write for the list of figures or list of tables, and protected@write tries to expand everything that is neither protected nor preceded by protect. You can use newrobustcmd* from the etoolbox package, that is slightly better.

          – frougon
          7 hours ago













          There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

          – frougon
          5 hours ago





          There was a spurious space at the end of your ExternalLink command. This changes everything! Please reread my answer...

          – frougon
          5 hours ago

















          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%2f501981%2fspacing-after-a-tikz-figure%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

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367